Hello Developers,
I am using OpenText's API to create folder with relation to the categories
(https://xyz.gov/ecms/cs.exe/api/v1/nodes)
My code is working fine, but what I am looking to avoid hardcoding in my JavaScript (see code below)
I got the problem to pass category ID as parameters, instead of "8966883" or "8966883_2" I am looking
to have passing parameter
Function createFolder(Parent_ID, rowData, arrCat) {
try {
$.su
pport.cors = true;
var matType = unEscape(arrCat[1].trim());
logString = logString + "--- function createFolder started, Parent_ID: " + Parent_ID + " " + " Date & Time: " + new Date() + "\n";
var url = Data[0][0].serverInfo + '/ecms/cs.exe/api/v1/nodes';
var form = new FormData();
form.append("type", "0");
form.append("parent_id", Parent_ID);
form.append("name", rowData[0]);
if (isDate(rowData[5]) & (isDate(rowData[6]))) {
var bodyData = {
roles: {
categories: {
"8966883": { // category
"8966883_2": rowData[0], //Matter Number
"8966883_4": matType, //Document Category - Matter Type
"8966883_5": rowData[1], //Document Description - Matter Title
"8966883_6": formaFinaltDate(rowData[5]),
"8966883_8": formaFinaltDate(rowData[6])
}
} // categories
} //roles
}
} //
else if (isDate(rowData[5]) & (!isDate(rowData[6]))) {
var bodyData = {
roles: {
categories: {
"8966883": { // category //8971533
"8966883_2": rowData[0], //Matter Number
"8966883_4": matType, //Matter Type
"8966883_10": rowData[1], //Document Description - Matter Title 7;9
}
} // categories
} //roles
}
}
else if (isDate(rowData[6]) & (!isDate(rowData[5]))) {
var bodyData = {
roles: {
categories: {
"8966883": { // category //8971533
"8966883_2": rowData[0], //Matter Number
"8966883_4": matType, //Matter Type
"8966883_5": rowData[1], //Document Description - Matter Title
"8966883_8": formaFinaltDate(rowData[6])
}
} // categories
} //roles
}
}
else if (!isDate(rowData[6]) & (!isDate(rowData[5]))) {
var bodyData = {
roles: {
categories: {
"8966883": { // category //8971533
"8966883_2": rowData[0], //Matter Number
"8966883_4": matType, //Matter Type
"8966883_5": rowData[1] //Document Description - Matter Title
}
} // categories
} //roles
}
}
form.append( "body", JSON.stringify( bodyData ) );
console.log("Test function token " + localStorage.getItem("token"));
$.ajax({
async: false,
processData: false,
mimeType: "multipart/form-data",
contentType: false,
data: form,
url: url,
type: 'POST',
crossDomain: true,
headers: {
"OTCSTICKET": localStorage.getItem("token")
},
contentType: false,
success: function (res) {
console.log(" Folder Created: " + JSON.stringify(res));
logString = logString + "--- createFolder was successful Matter Number: " + rowData[0] + new Date() + "\n";
},
error: function (res) {
console.log("Bad thing happend! " + JSON.stringify(res));
logString = logString + "--- createFolder wasn't successful Matter Number: " + " " + rowData[0] + " Response: " + JSON.stringify(res) + " " + new Date() + "\n";
}
});
}
catch (e) {
alert("Error " + e.message);
}
}//createFolder end
I am trying to avoid hardcoding and so far no success. Can someone help me with this issue