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

Syed N
Tera Contributor

So equipment assigned is dependent on the reference variable Leaver name.

once leaver name is populated there is a script include that runs which then fetches the alm_asset data of that leaver.

 

we can declare - cart.setVariable(item, 'equipment_assigned','');  

but how will it work with the script include

 

 

 

 

We dont need script include in this case. 

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

With above code we are getting leaver name in In.

After this you can glide alm_asset table based on "In".

Afer that you can set it using 

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


Raghav
MVP 2023

Syed N
Tera Contributor

Hi Raghav,

 

i have tried the above.

at present i am already getting the leaver name via the inbound action script.

i somehow need to be able to call the below in the script:

 

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

@Syed N this code is client code, willnot work in inbound action.

You can directly fetch information from alm_ asset table by gliding it directly from inbound action.


Raghav
MVP 2023

Syed N
Tera Contributor

@RaghavSh are you able to assist here apoligies my coding skills are not great.