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

Prateek Gupta3
Mega Guru

Hi,

 

Can you please check gr is referring to which object.

 

Thanks,

Prateek

Trupti6
Tera Expert

Hi,

 

Use current object instead of gr

I think in your script gr is not refering to any object

 

Thanks,

Tripti.

sushant007
Kilo Guru

if this is your complete script then your gr object is not defined and not referred to anything.

Replace it with current and try

chethann
Giga Contributor

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

// If Incident table
if (data.table == 'incident') {
if (action == 'withdrawal') {
// Withdrawal Incident
gr = new GlideRecord(data.table);
gr.addQuery('sys_id', data.sys_id);
gr.query();
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.addQuery('sys_id', data.sys_id);
gr.addQuery('number', data.number);
gr.update();
console.log('new sys_id :'+String(gr.sys_id));
}
}
}

 

I had change gr to current object, In the above case. it creating new incident with state as 'resolved'.