RITM state settings

Community Alums
Not applicable

Hi All,

 

I have written below code in run script activity of workflow to check state of tasks and accordingly set state of RITM, but it's not working. Please do suggest where I am lacking.

 

Workflow

Tejas12_0-1669622669163.png

 

 

Script

var cc = 0;
var ci = 0;
var cs = 0;
var other = 0;

var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.sys_id);
rec.query();

while (rec.next()) {
if (rec.getValue('state') == 3) {
cc++;
} else if (rec.getValue('state') == 4) {
ci++;
} else if (rec.getValue('state') == 7) {
cs++;
} else {
other++;
}
}

var ritm = new GlideRecord('sc_req_item');
if (ritm.get(current.getValue('request_item'))) {
if (ci > 0) {
ritm.setValue('state', 4);
} else if (cs > 0 && cc == 0 && ci == 0) {
ritm.setValue('state', 7);
} else if (cc > 0 && cs == 0 && ci == 0) {
ritm.setValue('state', 3);
} else {
gs.info('Some other combination of closed happened, not setting RITM state');
gs.info('Closed other count: ' + other);
}
}

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

Hi @Community Alums 

You don't need the 2nd glide record for the RITM, since you are already running the WF on the RITM table

You can just use, current to update value of the states, no need to use gliderecord here.

 

 

Best Regards
Aman Kumar

View solution in original post

4 REPLIES 4

Aman Kumar S
Kilo Patron

Hi @Community Alums 

You don't need the 2nd glide record for the RITM, since you are already running the WF on the RITM table

You can just use, current to update value of the states, no need to use gliderecord here.

 

 

Best Regards
Aman Kumar

Community Alums
Not applicable

Thanks @Aman Kumar S  it worked.

Awesome!

Glad it worked out

 

Best Regards
Aman Kumar

Jerick I
Kilo Sage
Kilo Sage

Hi @Community Alums,

 

Why not use GlideAggregate to obtain the state count? This will be much more efficient if you only need the count for each state. You make refer on this document Link and this dev blog Link