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.

How to get the value from RITM table insted of TASK table using email script.

Sudhansu12
Tera Contributor

Hi @Ankur Bawiskar 

I have a existing email Script where i need to get the value of "Description" and "Requested for"  field from RITM table for that purpose i have written a script.

 
var targetObj;
    if (current.getTableName() == "sysapproval_approver") {  
      var grCurrent = new GlideRecord(current.source_table);
        grCurrent.get(current.document_id);
        if (grCurrent) {
            targetObj = grCurrent;
        }
    } else if (current.getTableName() == "sc_task") {
        targetObj = current.parent;
    } else {
        targetObj = current;
    }
   

  above underline code i have used for fetch the Description and req_for field but it is not working.it fetch the data from sc_task table but i need it from RITM table

can any one help me on this.

 

1 REPLY 1

Deepak Shaerma
Kilo Sage
Kilo Sage

Hi @Sudhansu12 
just update your script as per the requirement

if (current.getTableName() == "sysapproval_approver") {
        // In case current record is an Approval record
        var grCurrent = new GlideRecord(current.source_table);
        if (grCurrent.get(current.document_id)) {

            if (grCurrent.getTableName() == 'sc_req_item') {
                ritm = grCurrent;
            } else if (grCurrent.hasField('request_item')) { // For example, if it’s a task associated with a RITM
                ritm = new GlideRecord('sc_req_item');
                ritm.get(grCurrent.request_item);
            }
        }
    } else if (current.getTableName() == “sc_task”) {
        // For tasks directly linked to RITMs
        ritm = new GlideRecord(‘sc_req_item’);
        ritm.get(current.parent); // Assuming ‘parent’ field links to RITM
    } else if (current.getTableName() == “sc_req_item”) {
        // If current record is an RITM already
        ritm = current;
    }

    if (ritm && ritm.isValidRecord()) {
        // Retrieve and store the description from the RITM record
        descriptionText = ritm.getValue(‘description’);
        
        // Retrieve the requested for user’s display name
        requestedForName = ritm.requested_for.getDisplayValue();
    }

    // Construct the message to be returned
    var finalMessage = "Description: " + descriptionText + "\nRequested For: " + requestedForName;

    return finalMessage;
})();

Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma