How to check if RITM requested for has replied

Community Alums
Not applicable

Hello Experts,

 

I have a requirement, If fulfillers want any information from requested for on RITM, they put RITM in "Awaiting User" state and wait for reply. If requestor for replies the RITM should move to Work In Progress state. 

 

This will happen from service portal, to achieve that I have written a after update business rule but it's working intermittently:

 

Condition: State is Awaiting User

 

Script:

(function executeRule(current, previous /*null when async*/ ) {

    var reqfor = current.variables.requested_for.email;
    var reqsysid = current.sys_id;
    var ritm = new GlideRecord('sys_journal_field');
    ritm.addQuery('element_id', reqsysid);
    ritm.addQuery('name', 'sc_req_item');
    ritm.addQuery('element', 'comments');
    ritm.orderbyDesc('sys_created_on');
    ritm.setLimit(1);
    ritm.query();

    var replyfrom = ritm.value.replyfrom;

    if (replyfrom==reqfor){
        current.state='2';
        current.update();
    }

})(current, previous);
 
Thanks,
Tejas

 

 

1 REPLY 1

Brian Lancaster
Tera Sage

Why are you only looking for the email? What if the user logs into the portal and just types in comments. Then there would be wording like Reply from like when you get a response from email. I would just change the BR to something like this. I have this setup for incident. You will need to update the code accordingly.

 

BrianLancaster_0-1724864980245.png

 

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var updated_by = gs.getUserID();
	//Allow Assigned to put the incident into Pending with Awaiting User Info or Awaiting User Confirmation
    if (updated_by != current.getValue('assigned_to')) { //prevent updates from the fulfiller setting back to WIP
		//Allows Caller, Opened By, and Watch List users to updated comments and set state back to in progress
        if (updated_by == current.getValue('caller_id') || updated_by == current.getValue('opened_by') ||
            current.getValue('watch_list').indexOf(updated_by) > -1) { //updated by can be caller, opened by or someone on the watch list.
            current.setValue('state', 2);
            current.setValue('incident_state', 2);
            current.setValue('hold_reason', '');
        }
    }

})(current, previous);