How to check if RITM has one sctask or many?

Sri56
Tera Contributor

Hi Team,

I have one biz rule on sc_task.

where, after update and state changes from pending to WIP, i need to check if current.request_item has multiple sctask, i need not to update.

In other way, if ritm has multiple sctask, i need to update the ritm status to WIP(state sync).

Can someone please help me know whether current ritm has 1 or more sc_task?

Thanks.

Sri

5 REPLIES 5

Sai Kumar B
Mega Sage
Mega Sage

Hi Author,

1.) Go to the RITM table

2.) Locate the specific RITM record

3.) In related lists you can check associated sc_tasks

find_real_file.png

SumanthDosapati
Mega Sage
Mega Sage

Hi,

You need to write script in business rule to check that.

var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request_item', current.request_item);
ritm.query();
var count = ritm.getRowCount();
gs.log(count);
if(count == 1)
{
//do here if ritm has only one sc task
}
else if(count > 1)
{
//do here if ritm has only more than one sc task
}

 

Mark as correct and helpful if it solved your query.

Regards,
Sumanth

Feel free to reach out if you have further questions or else you can mark an answer as correct and helpful to close the thread so that it benefits future visitors also.

Regards,
Sumanth

Hi Sumanth,

I am using above code on my business rule, where i have created a after update on sc_task table.

Condition: state changes from pending

and state changes to work in progress

my code:

(function executeRule(current, previous /*null when async*/ ) {
    var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('sys_id', current.request_item);
    ritm.query();
    var count = ritm.getRowCount();
    if (count == 1) {
        ritm.setValue('state', 2);
        ritm.update();
    }})(current, previous);

This is updating the status as expected,

But its creating new empty RITM record as below:

find_real_file.png

Please help me on how to fix this!

 

Thanks,

Sri