Assistance Needed for UI Action to Create 'P1 Incident' in ServiceNow Agent Mobile

IamSK
Mega Guru

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.

Community.PNG

 

 

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!

1 ACCEPTED SOLUTION

IamSK
Mega Guru

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.

https://www.servicenow.com/docs/bundle/xanadu-mobile/page/administer/tablet-mobile-ui/task/configure...

IamSK_1-1749046144594.png

 

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.

IamSK_4-1749046278342.png

 

IamSK_2-1749046178343.png

 

 

The variable 'sys_id' from the Input form screen will be passed into the script (parm_variable.sys_id) on the Action Step.

IamSK_0-1749046014062.png

Thank you for your continued assistance.

View solution in original post

7 REPLIES 7

YaswanthKurre
Giga Guru

To create a P1 incident from an existing record in the ServiceNow Agent app using Mobile App Builder, follow these steps:

1. Configure Data Parameters

In your "Open P1 Incident" Action item:

  • Add a Data Parameter named "current_incident_sys_id"
  • Set its value to reference the current record’s sys_id.

2. Update the Script

Use the "current_incident_sys_id" parameter to fetch the existing record and copy its values:

--Add this inside your execute function

// Get the sys_id of the current incident from the data parameter
var currentIncidentSysId = inputs.current_incident_sys_id;

// Fetch the current incident record
var currentIncident = new GlideRecord('incident');
if (currentIncident.get(currentIncidentSysId)) {
    // Create a new P1 incident
    var newIncident = new GlideRecord('incident');
    newIncident.initialize();
    
    // Copy fields from the current incident
    newIncident.short_description = currentIncident.short_description;
    newIncident.description = currentIncident.description;
    newIncident.category = currentIncident.category;
    newIncident.subcategory = currentIncident.subcategory;
    newIncident.priority = 1; // Set to P1
    
} else {
    //info message
}

 

Please mark this as helpful and correct if this resolves your issue.

 

Thanks,

Yaswanth

 

Thank you Yaswanth for your prompt response to my query.

 

I have followed your suggestions and added a 'Data Parameter' to the Action item, updating the script accordingly. When testing the app, I encountered a 'Failed' message. I hope I've implemented the changes as you described but apologize if I missed something.

Community 1.PNG

Community 2.PNG

Community 3.jpeg

 

Please let me know if there are any additional steps I might need to take to ensure the script functions correctly? Your continued assistance is much appreciated. 

Thanks again!

YaswanthKurre
Giga Guru

Hi Sk,

 

Please use insert() action to insert the incident record.

 

Add the Missing insert()Call: after line 19

 

Please mark this as helpful/ solved if this answers your question.

 

 

Yaswanth, 

 

I still see the 'Failed' message when testing in the app.

 

Please let me know if there are any additional steps I might need to take to ensure the script functions correctly? Your continued assistance is much appreciated.