gs.update() is not working properly?

chethann
Giga Contributor

Hi,

I tried the update the incident state to 'resolved', after click on 'Withdrawal' button by customer.

if (input && input.action) {
var action = input.action;

// If Incident table
if (data.table == 'incident') {
if (action == 'withdrawal') {
// Withdrawal Incident

gr.setValue('incident_state', 6);
gr.setValue('state', 6);
//gr.setValue('close_code', 'Resolved by Caller');
//gr.setValue('close_notes', 'test data by user');
gr.setValue('resolved_by', gs.getUserID());
gr.setValue('resolved', gs.nowDateTime());
gr.update();

}
}

While updating the incident, it creating a new incident with same incident number and different sys_id and updating as 'resolved'.

is anyone faced the same issue or any suggestion in above code.

1 ACCEPTED SOLUTION

Can you confirm if "Withdrawal" is present on incident table and if yes please use following:

if (input && input.action) {
var action = input.action;

// If Incident table
if (data.table == 'incident') {
if (action == 'withdrawal') {
// Withdrawal Incident
var gr = new GlideRecord(data.table);
gr.addQuery('sys_id', data.sys_id);
gr.query();
if(gr.next()){
gr.setValue('incident_state', 6);
gr.setValue('state', 6);
gr.setValue('resolved_by', gs.getUserID());
gr.setValue('resolved', gs.nowDateTime());
gr.update();
}
console.log('new sys_id :'+String(gr.sys_id));
}
}
}

}

View solution in original post

6 REPLIES 6

Can you confirm if "Withdrawal" is present on incident table and if yes please use following:

if (input && input.action) {
var action = input.action;

// If Incident table
if (data.table == 'incident') {
if (action == 'withdrawal') {
// Withdrawal Incident
var gr = new GlideRecord(data.table);
gr.addQuery('sys_id', data.sys_id);
gr.query();
if(gr.next()){
gr.setValue('incident_state', 6);
gr.setValue('state', 6);
gr.setValue('resolved_by', gs.getUserID());
gr.setValue('resolved', gs.nowDateTime());
gr.update();
}
console.log('new sys_id :'+String(gr.sys_id));
}
}
}

}

its working now, but the response took more time than usual by using the above code changes.

Do you have any idea?