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.

Encounter Business Rule Script Processing Issue.

Meera_P
Tera Expert

Hello,

I'm currently learning about Business Rule Scripts, but I've encountered an issue. While the business rule runs on sc_req_item table without errors, it fails to correctly populate the 'requested for' name in the 'sc_task'.

Can someone please help review the code and let me know where I did incorrectly.  Thank you

 

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

    var gr = new GlideRecord('sc_task');
    gr.initialize();
    gr.request_item = current.sys_id;

    var senderName = getUserByEmail('abraham.lincoln@example.com');
    if (senderName) {
        gr.request_item.requested_for = senderName;
        gr.description = "Requester: " + senderName;
    } else {
        return null;
        //gs.info("Unable to find user for email: abraham.lincoln@example.com");

    }
    gr.insert();

})(current, previous);

// Function to get name from sys_user table based on email
function getUserByEmail(userEmail) {
    var userGR = new GlideRecord('sys_user');
    if (userGR.get('email', userEmail)) {
        // return userGR.name.toString(); 
        return userGR.getUniqueValue();
    } else {
        return null;
    }
}

 

 

7 REPLIES 7

Hi,
1/ before adding the field to the form you will need to add\create the new field on your table.
Then add the field to the form - it may be added to the form by the platform during creation, but unlikely to be positioned where you want it.
2/ Once you have added the field to the form you can show\hide the field using UI policy (preferred option) or an onLoad client script.
3/ No customizations are not overwritten by upgrade, but you will find skipped upgrade records relating to form/list layouts and any customized OOB scripts.

Kavita_Bhojane
Tera Guru

Hi @Meera_P ,

 

Ideally different requesters should have different RITMs under single request. If you look at the dictionary info of "Requested for" on "sc_task" table , is requested_for of the related "sc_req_item" record.

 

Please mark my answer helpful and accept as a solution if it helped 👍✔️

Thanks,
Kavita Bhojane

Kavita_Bhojane
Tera Guru

Hi @Meera_P ,

 

Thank you for acknowledging my response as helpful.
If my assistance proved beneficial, please mark it as correct and close the thread to benefit future readers.

 

Regards,
Kavita Bhojane