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

Ok, but what information you need from alm_asset table based on leaver name? I can write script accordingly.


Raghav
MVP 2023

Syed N
Tera Contributor

I need the asset tag and the display name of the asset

 

so for example M1123 - Dell intel Vpro

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

var asset_tag1;

var asset = new GlideRecord('alm_asset');

asset.addQuery('asigned_to',ln);

asset.query();

if(asset.next())

{

asset_tag1 = asset.asset_tag + " - "+asset.display_name;

}

 

after that add below line in your cart code:

 

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

 

Note: equipment_assigned is a string variable and leaver should have only 1 asset assigned to him/her.


Raghav
MVP 2023

Syed N
Tera Contributor

Hi Raghav, 

 

Thanks for the above code.

Please note that i had to remove the following lines:

 

var ln = '';
var br = new GlideRecord('sys_user');

 

as it mentioned in the inbound email script that they had already been declared.

 

the IEA was able to pull back asset details however after running tests it is not pulling back the correct asset(s)

 

its pulling back the following:

 

SyedN_0-1670926451667.png

 

Looks like the same asset is pulling back to all leaver users.

 

 

It is based on your leaver.

Check your table, either your lever have multiple assets assigned, in that case you need to figure out which asset to show.

 

Also in this case the asset tag is missing, that means the asset tag is missing in your table.

Multiple Leavers can have asset with same display name so it's not showing same for all.

 

make below change to your code and check, you will see different sys_ids.

 

asset_tag1 = asset.sys_id + " - "+asset.display_name;


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023