how to perform lookup when the walkup interaction form is loaded ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2023 04:03 PM
i am new in scripting . need some help i have set the asset field as a reference to alm_hardware table but how to populate the asset field based on the opened by user ?
- Labels:
-
Service Catalog
-
Walk-Up Experience
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2023 04:13 PM
Hi, if you have a single asset mapped to each user, you could use an onChange client script for the Opened For field.
When 'Opened For' changes\is populated, use GlideAjax to look up your asset record returning the users Asset and setting it in the 'asset' field.
Client Side API | ServiceNow Developers
If the user has multiple Assets in their name, then you would probably need to use a reference qualifier on the 'asset' field so that the assets available for selection are limited to those associated to your 'Opened For' user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2023 05:08 PM - edited 12-10-2023 05:52 PM
is this the one that you are referring to ?
getDetails: function(){
var arr = [];
var sysId =this.getParameter('sysparm_sysId');
var gr = new GlideRecord('alm_hardware');
gr.addQuery('assigned_to', sysId);
gr.query();
while(gr.next()){
arr.push(gr.asset_tag.toString());
}
if(arr.length > 0)
return arr.toString();
else
return '';
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 04:03 AM
@Tony Chatfield1 i used chat gpt and it gave me this. i tried doing it but i cannot amend the walkup experience in the studio. any other ways of doing it ?
To create a field on a ServiceNow Walk-up Interaction form that looks up user assets from the alm_hardware table based on the opened_by field, you can use a combination of reference fields, client scripts, and possibly a Script Include for server-side processing. Below are the steps to achieve this:
1. Create a Reference Field on Walk-up Interaction Table:
- Navigate to ServiceNow Studio > Tables.
- Open the Walk-up Interaction table.
- Create a new reference field, let's call it user_asset.
- Set the Reference field to reference the alm_hardware table.
- Configure the Reference Qualifier if necessary to filter assets based on the opened_by field.
2. Create a Client Script:
- Navigate to ServiceNow Studio > Scripts - Client Scripts.
- Create a new Client Script and name it something like WalkupInteractionClientScript.
- In the script, use the onLoad function to trigger the lookup when the form loads:
3. Create a Server-Side Script Include:
- Navigate to ServiceNow Studio > Scripts - Script Includes.
- Create a new Script Include and name it something like YourScriptIncludeName.
- In the script include, create a function to process the server-side request:
4. Add Client Script to the Form Layout:
- Go to ServiceNow Studio > Forms.
- Open the Walk-up Interaction form.
- Add the WalkupInteractionClientScript to the form layout.
5. Test the Walk-up Interaction Form:
- Create or open a Walk-up Interaction record.
- Select a user in the opened_by field.
- The user_asset field should automatically populate with the assets associated with the selected user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 03:31 AM - edited 12-15-2023 03:53 AM
i tried to use this script but when the walkup interaction loads, i am not getting any data in the serial_number box
function onLoad() {
var openedForValue = g_form.getValue('opened_for'); // Replace 'opened_for' with the actual field name
if (openedForValue !== '') {
var ga = new GlideAjax('MyScriptInclude');
ga.addParam('sysparm_name', 'getAssignedTo');
ga.addParam('sysparm_opened_for', openedForValue);
ga.getXMLAnswer(function(answer) {
if (answer !== ' ') {
g_form.setValue('serial_number', answer); // Replace 'assigned_to' with the actual field name
}
});
}
}
script include:
var MyScriptInclude = Class.create();
MyScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSerialNumber: function() {
var openedForSysId = this.getParameter('sysparm_ast'); // Assuming opened_for is a reference field to sys_user
var gr = new GlideRecord('alm_hardware');
gr.addQuery('opened_for', openedForSysId);
if (gr.next()) {
var assignedToSysId = gr.assigned_to; // Assuming assigned_to is a reference field to sys_user
var assignedToGR = new GlideRecord('sys_user');
if (assignedToGR.get(assignedToSysId)) {
var userName = assignedToGR.user_name;
return userName;
}
}
return ''; // Return an appropriate value if no matching record is found or any other error
}
});