JS API batch keyword


(Danny Ngo) #1

I’m trying to utilize the batchRequest operation to use the response of the createAsset ID to be use in the editMetadataSchema function. So basically I’m trying to clone an exciting asset metadata into a new metadata schema.
I’ve read this post about a workaround on parsing the keywords within the batch operation and try suggested solution with no luck of retrieving ID respond on createAsset function.

here is the below code

function getAsset() {
var parent = document.getElementById(“newrent”).value;

js_api.getChildren({
“asset_id”:“204050”,
“levels”:2,
“type_codes”:[
“page_standard”
],
“link_types”:[
“SQ_LINK_TYPE_1”,
“SQ_LINK_TYPE_2”
],
“get_attributes”:0,
“dataCallback”:cloneObject
})

}

function cloneObject(object) {
var id;
var sname;
var str = JSON.parse(JSON.stringify(object));
alert(str);
for(var i = 0;i < str.length;i++){
id = str[i].asset_id;
sname = str[i].name;
idArray.push({“id”:str[i].asset_id});

 js_api.batchRequest({

“functions”:{
“0”:{
“function”:“getMetadata”,
“args”:{
“asset_id”:id
},
“blocking”:1
},
“1”:{
“function”:“createAsset”,
“args”:{
“parent_id”:364915,
“type_code”:“page_standard”,
“asset_name”:sname,
“link_type”:1
}
},
“2”:{
“function”:“editMetadataSchema”,
“args”:{
“assetid”:"%results_0_1_id%",
“schemaid”:“364176”,
“set”:1,
“granted”:0,
“cascades”:0
}
}
},
“dataCallback”:finish
});

}

}

Danny


(Jamie Edgar) #2

i’m wondering if you are just spelling keyowrd incorrectly to attract attention?
maybe you should consider proofreading all data that you input more thoroughly…
perhaps there is a simple typo elsewhere that you may have overlooked?
gigo comes to mind :wink:


(Danny Ngo) #3

Hi Jamie,

Thanks for replying. Yes, that was the idea to attract attention only joking I was in a rush to post the question.
Hmm, I’m sure there no typo and the batchRequest runs fine when I remove the editMetadataSchema function so I’m sure the keyword replacement is not retrieving the ID from the createAsset function response.


(Bart Banda) #4

Hmm, that’s strange, does sound like a bug. WHat version of Matrix are you using?

Alternatively, you could run it as 2 separate calls as a workaround. Run editmetadataschema after the batch has completed.

Second option is to use a trigger to apply it, or maybe apply the metadata schema to the parent location of where the asset is getting created so it automatically inherits the schema?


(Danny Ngo) #5

Hi Bart,

We are on V5.2.9.0.

Thanks for the suggestion the work around work fine. I’ve separated it into two calls and then parse the respond to retrieve the id from the createAsset method.

Thanks

Danny