Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Show error message on RITM without close compaleting SC TASKS

ShaziyaS4380655
Tera Contributor

HI community,

 

I want to show error message on RITM when user tries to close RITM if SC tasks are not closed complete, i am not allowed to use BR. is there any way to accomplish this requirement.

3 ACCEPTED SOLUTIONS

Me Being Mustaq
Tera Guru

Assalamualaikum @ShaziyaS4380655 ,

 

yes, you can do it by using  Use a UI Policy + Client Script   or Flow Designer with Error Logging

 

You may find below thread helpful:

 

If it is helpful, please hit the thumbs button please mark the answer as correct based on the impact!!

 

Kind Regards,

Shaik Mohammed Mustaq

 

 

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@ShaziyaS4380655 

how are they closing RITM?

Are they changing the State field and then saving?

If yes then Make State field as Readonly using onLoad client script + Display business rule if RITM has any 1 Catalog Task as Open

Something like this, please enhance

Display BR on RITM Table:

(function executeRule(current, previous /*null when async*/ ) {
	
    // Query catalog tasks related to this RITM with state not closed
    var taskGR = new GlideRecord('sc_task');
    taskGR.addQuery('request_item', current.sys_id);
    taskGR.addActiveQuery();
    taskGR.setLimit(1); // We only need to check if any open task exists
    taskGR.query();

    g_scratchpad.hasOpenTask = taskGR.hasNext();

})(current, previous);

onLoad Client Script on RITM

function onLoad() {
    // Check if server-side determined flag exists
    if (g_scratchpad.hasOpenTask && !g_form.isNewRecord()) {
        // Make the State field readonly
        g_form.setReadOnly('state', true);

        // OR you can also remove the choice value of Close Complete using g_form.removeOption('state',3);

    }
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

@ShaziyaS4380655 

you want to show error message or do some validation on UI.

Here flow won't help as it runs in server side.

The approach I shared should work fine based on which approach customer wants to take.

I believe I shared working solution for your question.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Me Being Mustaq
Tera Guru

Assalamualaikum @ShaziyaS4380655 ,

 

yes, you can do it by using  Use a UI Policy + Client Script   or Flow Designer with Error Logging

 

You may find below thread helpful:

 

If it is helpful, please hit the thumbs button please mark the answer as correct based on the impact!!

 

Kind Regards,

Shaik Mohammed Mustaq

 

 

@Me Being Mustaq 
Walaikumassalam
SInce  it is OOTB iam not allowed to write BR's,Client script, UI polciy

Hi @ShaziyaS4380655 ,

 

Flow Designer can be used for customization, even in OOTB setups if permitted. You can trigger a flow when the RITM state changes, add a decision step to check if any related records are not "Closed Complete," and if there are open tasks, set a field on the RITM. Optionally, you can log an error or send a notification.

After that, use form layout or read-only conditions (if allowed) to prevent closure based on the value of that field.

 

If it is helpful, please hit the thumbs button please mark the answer as correct based on the impact!!

 

Kind Regards,

Shaik Mohammed Mustaq

 

 

 

 

 

inorder to add the trigger as when RITM state changes to closed complete , i dont see the sc_req_item into the table field