current.update() not working in script action

Milan13
Giga Expert

Hello,

I have a script action which reacts to an event in a business rule, after this event is triggered I need certain fields to be updated, even if the script action reacts to the event according to log, "current" parameters are accessible within the script according to log, current.update() does not work for some reason...

Script action:

gs.log('!!!MILAN - STORY43....');
setFields();

function setFields() {

current.state = '9';
current.short_description = 'Test from script action';
current.assigned_to = "";
gs.info('!!!MILAN' + current.assigned_to + current.state + current.short_description);
current.update();

}

 

gs.info in log works with the correct values, however what does not work is the current.update() part as the data on the incident form do not get updated..

Any idea why?

Appreciate your help,

Milan

find_real_file.png

Log (gs.info('!!!MILAN' + current.assigned_to + current.state + current.short_description);

find_real_file.png

 

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Hello Milan,

try out with below code:

var grIncident = new GlideRecord('incident');
grIncident.addQuery('sys_id',current.sys_id);
grIncident.query();
while(grIncident.next()){
grIncident.short_description = "Test from script action";
grIncident.setValue('assigned_to','');
grIncident.update();
}


Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

View solution in original post

14 REPLIES 14

Omkar Mone
Mega Sage

Hi 

Why don't you try writing a glide record and then update?

Milan13
Giga Expert

I tried below code as well but not working anyway...

 

gs.log('!!!MILAN - STORY43....');
setFields();

function setFields() {


gs.info('!!!MILAN' + current.assigned_to + current.state + current.short_description);

var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('number', current.number);
incidentGR.query();
while (incidentGR.next()) {
incidentGR.state = '9';
incidentGR.assigned_to = '';
incidentGR.update();
}

}

Hi 

Why don't you do it with quering sys_id? Something like this 

var incidentGR = new GlideRecord('incident');
incidentGR.addQuery('sys_id', current.sys_id);
incidentGR.query();
if(incidentGR.next()) {
incidentGR.setValue('incident_state','9');
incidentGR.setValue('assigned_to',"");
incidentGR.update();
}

Unfortunately, it does not work, even if it probably should...:(