Limiting choices for state field in Mobile APP

Barnali Rakshit
Tera Contributor

I need to limit the choices for state field when assigning tasks in mobile app.

I have tried with mobile UI policy and also created client scripts on load and change (using remove options) but could not made it  to work.

Could you please help to find options how to make it work.

Description for the task:

 Open mobile app

Assign the task

Change state(it should only show few options/choices)like work done , work in progress .In hold...

I am unable to do now , need help !!!

3 REPLIES 3

Sanika Subhash
Tera Expert

Hi Rak**bleep**,

 

To limit the choices for the State field when assigning tasks in the ServiceNow mobile app, you can use a UI Policy combined with a client script. Here's how you can achieve this:

1. Go to the relevant table (e.g., Task) and navigate to `UI Policies`.
2. Create a new UI Policy with the following settings:
- Table: Task
- Type: Mobile
- Name: Limit State Choices
- Description: Limit the choices for the State field in the mobile app
3. Configure the UI Policy conditions based on your requirements. For example, you can set the condition to `true` or specify a specific condition that triggers the policy.
4. Add a new UI Policy Action with the following settings:
- Action: Hide
- Field: state
5. Specify the desired State values to hide in the "Hide for Choices" field. For example, if you want to hide the "In Progress" and "On Hold" options, enter `In Progress, On Hold`.
6. Save the UI Policy.

Next, you need to create a client script to remove the hidden options from the State field in the mobile app. Here's how you can do it:

1. Go to the relevant table (e.g., Task) and navigate to `Client Scripts`.
2. Create a new client script with the following settings:
- Table: Task
- Type: Mobile
- Name: Remove Hidden State Options
- Description: Remove hidden options from the State field in the mobile app
3. In the "Script" field, add the following code:

function onLoad() {
g_form.setDisplay('state', false);
g_form.setDisplay('state_label', true);
}


4. Save the client script.

With these configurations in place, the State field in the mobile app will only display the allowed choices according to the UI Policy. The client script will hide the State field and display a label instead.

Regarding increasing the character limit on the workflow switch, you can adjust the field length by modifying the corresponding field properties. Here's how:

1. Go to the relevant table (e.g., Task) and navigate to `Dictionary`.
2. Search for the State field and open its record.
3. Increase the "Max length" field to the desired character limit.
4. Save the record.

 

Please mark this as helpful and correct.

Thanks,

Sanika

SanketLandge1
Kilo Guru

Hello @Barnali Rakshit,

 

You can use gs.isMobile()  on a display BR and set a scratchpad variable based on this. In the client script just read that scratchpad value and set the choices you want to show.

 

Mark this as helpful or correct if it helps you so others can find it easily.

 

Thanks,
Sanket Landge

 

Hello @Barnali Rakshit ,

 

Create a client script and call the script include.

 

with below condition:

 

If(gs.isMobile() ==true) {

your logic to show/hide options.

}

 

Mark this as helpful or correct if it helps

 

Thanks,

Sanket Landge