Pull the data from customer instance to our instance and update the incident record

sahana hattikal
Tera Contributor

Hi Team,

 

we have integration between two instances . Once the incident ticket created in our instance the same should be created in the customer instance and the customer ticket number is stored in secondary correlation id in our instance and our ticket number is stored in the customer's correlation id  and update is happening from there end but it should update our incidents through GET API.

 

I have created the datasource and calling the secondary correlation id through script include 

 

this is my script include :

secnumber : function(){
var array = [];
 
var gr = new GlideRecord('incident');
//gr.addActiveQuery();
gr.addEncodedQuery('u_sec_correlation_id!=NULL');
gr.query();
 
while(gr.next()){
//var secid = gr.getValue('u_sec_correlation_id');
array.push(gr.u_sec_correlation_id.toString());
gs.log('from the script include' + gr.u_sec_correlation_id); // here the output I am getting in this way
sahanahattikal_0-1690901360548.png

 

}
for(var i=0;i<array.length;i++){
/
 
return array[i]; //but here I am getting only 1 ticket number
}
}

 Can some one help me how this array can be executed multiple times like how i am getting output for above

 This is the Data source

var tokenUtils = new global.BASFFederationUtils();
tokenUtils.authenticate();
var sec_number = new VerifyGroupMember().secnumber();
//var number = current.sys_id;
//var tab = 'incident';
//var number =
//var number =
var request = new sn_ws.RESTMessageV2('Create_inc_basf', 'Query Data');
//request.setStringParameterNoEscape('table', tab);
request.setStringParameterNoEscape('access_token', tokenUtils._isTokenAvailable());
request.setStringParameterNoEscape('number', sec_number);
gs.log('the second number' + sec_number);  // i am getting only value here all the time, rest of the tickets are not updating
var response = request.execute();
var responseBody = response.getBody();
// var queryString = response.getQueryString();
var httpstatus = response.getStatusCode();
gs.log("Pull BASF Body is " + responseBody);
gs.log("Pull BASF status is " + httpstatus);
var obj = JSON.parse(responseBody);

var length = Object.keys(obj.result).length;
var str = JSON.stringify(obj);
var parser = new JSONParser();
var parsed = parser.parse(str);
gs.info("BASF " + length);
for (var i = 0; i < length; i++) {

 



var shortDescription = parsed.result.answer.items[i].value.short_description;
var Description = parsed.result.answer.items[i].value.description;
var Number = parsed.result.answer.items[i].value.correlation_id;

gs.log('the number is' + Number);
var WorkNotes = parsed.result.answer.items[i].value.work_notes;
var CloseNotes = parsed.result.answer.items[i].value.close_notes;
var State = parsed.result.answer.items[i].value.state;
var Solution = '';
var Comments = parsed.result.answer.items[i].value.comments;
var ServiceOffering = parsed.result.answer.items[i].value.service_offering;
//var Cause = "Issue from BASF"
var map = {};
//map['name'] = name;
map['short_description'] = shortDescription;
map['number'] = Number;
map['description'] = Description;
map['state'] = State;
map['work_notes'] = WorkNotes;
map['comments'] = Comments;
map['close_notes'] = Solution;
map['service_offering'] = ServiceOffering;
//map['cause']


import_set_table.insert(map);


}

0 REPLIES 0