- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2025 08:39 PM
Hello community,
I am working on implementing a feature in the ServiceNow Agent mobile app using Mobile App Builder. My goal is to create a UI action in the 'Event Incident Records' section that allows the creation of a 'P1 Incident' by copying values from an existing record.
I have already started by creating a function called ‘Open P1 Incident’ with an Action item. The Action item includes sections such as script, input form screen, field values, and data parameters. Since no user input is needed, I have eliminated the input form screen section.
However, I am facing difficulties in grabbing values from the current record using the script. I've tried updating the script with inputs and outputs but am stuck on where to specify these input and output values.
Could anyone provide guidance or examples on how to achieve this? Any help would be greatly appreciated as I am new to mobile app development in this context.
Thank you in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2025 07:12 AM
Yaswanth, thank you for your time and help. It means a lot. I was able to get the logic and make it work. Here is the solution.
Documentation from the ServiceNow really helped me. This is the link how I was able to create action item with action step.
Instead of using 'script' in the Action item, I used 'Multistep' and created an Action Step with Script. Additionally, I created an Input form screen with variables 'sys_id' of type 'Database field,' adding the attribute of 'FieldName,' and attached the input form to the Action item.
The variable 'sys_id' from the Input form screen will be passed into the script (parm_variable.sys_id) on the Action Step.
Thank you for your continued assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2025 09:04 AM
Hi Sk,
Please add info/debug messages in the script and validate the logs.
Try this updated script :
function execute(inputs, outputs) {
try {
var currentIncidentSysId = inputs.current_incident_sys_id;
var currentIncident = new GlideRecord('incident');
if (!currentIncident.get(currentIncidentSysId)) {
throw "Incident not found: " + currentIncidentSysId;
}
var newIncident = new GlideRecord('incident');
newIncident.initialize();
newIncident.short_description = currentIncident.short_description;
newIncident.description = currentIncident.description;
newIncident.category = currentIncident.category;
newIncident.subcategory = currentIncident.subcategory;
newIncident.priority = 1; // P1
newIncident.assigned_to = currentIncident.assigned_to; // Optional, if required
newIncident.caller_id = currentIncident.caller_id; // Optional, if required
if (newIncident.insert()) {
outputs.result = "New P1 Incident created: " + newIncident.sys_id;
} else {
throw "Failed to create incident. Check script logs.";
}
} catch (e) {
outputs.error = e.message;
gs.error(e.message);
}
}
Thanks,
Yaswanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2025 06:36 AM
Yaswanth, thank you for your response.
I did not observe any logs being generated in the system logs. It is possible that the code for mobile view may differ in how logs are displayed.
Could you please advise if there are any additional steps I should take to ensure the script functions correctly? Your continued assistance is greatly appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2025 07:12 AM
Yaswanth, thank you for your time and help. It means a lot. I was able to get the logic and make it work. Here is the solution.
Documentation from the ServiceNow really helped me. This is the link how I was able to create action item with action step.
Instead of using 'script' in the Action item, I used 'Multistep' and created an Action Step with Script. Additionally, I created an Input form screen with variables 'sys_id' of type 'Database field,' adding the attribute of 'FieldName,' and attached the input form to the Action item.
The variable 'sys_id' from the Input form screen will be passed into the script (parm_variable.sys_id) on the Action Step.
Thank you for your continued assistance.