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

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

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.

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.