Inbound Email Action Submits catalog request- i need to autopopulate a field before submission

Syed N
Tera Contributor

Hi,

 

I have an Inbound email action that automatically populates variables on a catalog item and submits a sc_req_item.

on the catalog item there is an 'On Change' catalog client script which runs when a particular field 'Leaver Name' is populated, this then fetches a users asset information and displays it within a text field called 'Equipment Assigned' - Please see catalog script below:

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

if(newValue == '')
g_form.clearValue('leaver_name'); // give correct variable name here

if(oldValue != newValue){

var ga = new GlideAjax('GetAssetTags');
ga.addParam('sysparm_name', "getDetails");
ga.addParam('sysparm_userID', newValue);
ga.getXMLAnswer(function(answer){
if(answer != ''){
g_form.setValue('equipment_assigned', answer); // give correct variable name here
}
});
}
//Type appropriate comment here, and begin script below

}

 

I know that this can only be run on the catalog form itself, however is there a way to automatically run during the inbound email action process.

so in theory what I want to achieve is the following:

1. inbound email action runs

2. all variables are filled including the leaver name 

3. the client script on change runs automatically when the requested item is created populating the 'Equipment Assigned' field.

 

do I need to use a business rule or an onSubmit catalog client script instead.

1 ACCEPTED SOLUTION

@Syed N there is a spelling mistake, correct it:

asset.addQuery('assigned_to',ln);

The above code has single s in assigned_to


Raghav
MVP 2023

View solution in original post

19 REPLIES 19

Vasantharajan N
Giga Sage
Giga Sage

You can definitely achieve it using the Inbound Email Flow which is our low code to no code platform. So please give it a try and let us know for further support.

 

FYR - Just a heads-up to start with

 

Capture.JPG

 


Thanks & Regards,
Vasanth

RaghavSh
Kilo Patron

You can handle it with after insert BR or your inbound action script only. 

on submit and on change are client side scripts which need client interactions, incase of creating request through inbound email there is no manual interaction/ changes on form so it may not work.


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023

Syed N
Tera Contributor

Hi Raghav, 

 

Thank you for the reply, are you able to share how i can do this.

 

my current inbound email action script is the following:

 

// The Inbound Email Action for MIM Leavers script
// Author: David/ Syed
//Date: 08/12/22
// Target table: sc_req_item

//Function to get Variables from Email
var esubject = email.subject;
var ebody = email.body_text;
var manager = email.body.submitted_b; // Variable can be extracted from the email body, in the format of "name:value" pairs.
var leaver = email.body.leaver_name;
var date = email.body.leave_date;

//Functions to populate reference variables on catalog item
//new segment to get submitted by
var sb = '';
var gr = new GlideRecord('sys_user');
if (gr.get('name', email.body.submitted_by)) {
sb = gr.sys_id;
}

//new segment to get submitted by
var ln = '';
var br = new GlideRecord('sys_user');
if (br.get('name', email.body.leaver_name)) {
ln = br.sys_id;
}

//Sys_id of catalog item
var cart = new Cart(); //calling the cart AP
var item = cart.addItem('3c8851f51b83551062db85e4464bcb5e');
var ritm = new GlideRecord('sc_req_item');

createRequest();

function createRequest() {
cart.setVariable(item, 'subject', email.subject);
cart.setVariable(item, 'submitted_by', sb);
cart.setVariable(item, 'leaver_name', ln);
cart.setVariable(item, 'leave_date', date);
cart.setVariable(item, 'mim_detail', ebody);

//Update requested_for in Cart
cart.cart.requested_for=ln;
cart.cart.update();

var rc = cart.placeOrder(); //this launches the catalog item, and creates a request object. rc = the request object

updateRITM(rc.sys_id);
//call a function immediately to update the ritm. This must be a nested function, otherwise inbound actions get weird.
//also, we're passing the sys_id of the request so we know what RITM to grab.

// Update the Request fields (using rc record)
rc.opened_by = sb;
rc.requested_for = ln;
rc.update();

}

function updateRITM(req) {

var ritm = new GlideRecord('sc_req_item');

ritm.addQuery('request', req); //req is what we passed from the previous function. the sys_id of the request.

ritm.query();

// update Opened By
if(ritm.next()) {
ritm.opened_by = sb;
ritm.update();
}

}

event.state = "stop_processing"; //stop evaluating inbound actions. This is why I keep this record's order lower than my incident from email rules.

what value should variable "equipment_assigned" have ? also which table stores this information? what is the relationship between "leaver_name" and "equipment_assigned"? based on that we can get the value and set it using :

 

cart.setVariable(item, 'equipment_assigned','');  


Raghav
MVP 2023