Help with payload script include

Thomas98
Tera Expert

Hi, 

Can someone please help or gudie me in the right direction.

I'm kinda of stuck with payload for remote spoke ebonding. Destination has sub state  "On hold Reason" and my source has no "On hold reason"  (i am the source)

Below is the mapping I'm trying to map 

Thomas98_0-1740539710127.png

 

Source  to Destination  
New > New
Active > In Progress
Awaiting Problem > On Hold - awaiting problem
Awaiting User Info > On Hold - awaiting user
Awaiting Evidence > On Hold - awaiting user
Resolved > Resolved
Closed > Closed
 
            correlation_display: this.correlation_display,
            short_description: incidentRec.getDisplayValue('short_description'),
            state: incidentRec.getDisplayValue('state'),
            state: incidentRec.getValue('state'),
			state: this.stateMappingOut(incidentRec.getValue('state')),
            //hold_reason: incidentRec.getDisplayValue('hold_reason'),
            caller_id: incidentRec.getDisplayValue('caller_id'),
            business_service: incidentRec.getDisplayValue('business_service'),
            category: incidentRec.getDisplayValue('category'),
            subcategory: incidentRec.getDisplayValue('subcategory'),
            impact: incidentRec.getValue('impact'),
            urgency: incidentRec.getValue('urgency'),
            u_external_incident_number: incidentRec.getValue('u_external_incident_number'),
			assignment_group: incidentRec.getValue('prime: assignment_group'),
			// close_code: incidentRec.getValue('close_code'),
            close_notes: incidentRec.getValue('close_notes'),
        };

        if (incidentRec.state == '6') {
            if (incidentRec.close_code == "Resolved by Vendor") {
                incidentValues.close_code = "Solved By Vendor";
            } else {
                incidentValues.close_code = "Solved Remotely (Permanently)";
            }
        }

        return incidentValues;
    },

    buildDesc: function(incidentRec) {
        var desc = "Caller: " + incidentRec.getDisplayValue('caller_id');
        desc += "\nLocation: " + incidentRec.getDisplayValue('location');
        desc += "\nCI: " + incidentRec.getDisplayValue('cmdb_ci');
        desc += "\nCategory: " + incidentRec.getDisplayValue('category');
        desc += "\nSubcategory: " + incidentRec.getDisplayValue('subcategory');
        desc += "\n\n" + incidentRec.getDisplayValue('description');
        return desc;
    },

    stateMappingOut: function(state, substate) {
        if (state == 3 && !substate.nil()) {  //awaiting problem
            if (state == 4) { //Awaiting User
                return "4";  //Awaiting User Info
            } else if (substate == 3) { //Awaiting Problem
                return "3"; //Awaiting Problem
            } else {
                return "5"; //Awaiting Evidence
            }
        } else {
			return state;
		}
    },

    escalateIncidentPayload: function(incident_sys_id) {
        var incidentSysId = incident_sys_id;
        var incidentRec = new GlideRecord('incident');
        incidentRec.get(incidentSysId);
        var incidentValues = {
            assignment_group: "Support 1",
        };

        return incidentValues;
    },

    createRequestPayload: function(task_sys_id) {
        var taskSysId = task_sys_id;
        var taskRec = new GlideRecord('sc_task');
        taskRec.get(taskSysId);
        var taskValues = {
            state: taskRec.getDisplayValue('state'),
            u_resolution: taskRec.getDisplayValue('close_notes')
        };

        return taskValues;
    },

    createWorknote: function(task_sys_id) {
        var taskSysId = task_sys_id;
        var taskRec = new GlideRecord('task');
        taskRec.get(taskSysId);
        var taskValues = {
            work_notes: taskRec.work_notes.getJournalEntry(1),
        };

        return taskValues;
    },

    createComments: function(task_sys_id) {
        var taskSysId = task_sys_id;
        var taskRec = new GlideRecord('task');
        taskRec.get(taskSysId);
        var taskValues = {
            comments: taskRec.comments.getJournalEntry(1),
        };

        return taskValues;
    },

    type: 'SSNPayloadbuilder'
};

 

 

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@Thomas98 

you can use IF else logic and compare the value with source and then set the target

what script did you try so far?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

I didnt get much further. I was struggling with the below code to call substate. 

Can you help me please?

 

 stateMappingOut: function(state, substate) {
        if (state == 3 && !substate.nil()) {  //awaiting problem
            if (state == 4) { //Awaiting User
                return "4";  //Awaiting User Info
            } else if (substate == 3) { //Awaiting Problem
                return "3"; //Awaiting Problem
            } else {
                return "5"; //Awaiting Evidence
            }
        } else {
			return state;
		}
    },

 

@Thomas98 

where are you checking the substate source value and returning the target value?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

So, I have flow “Incident Update” followed by an action flow which calls the payload.

 

what time trying to achieve is, when I change the state to awaiting user Info, I want it to change in the destination to 

State : On Hold, Substate “ Awaiting user info”