Clear the field's value in the mobile app
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 10:57 PM
How to clear field "A" value if value of field "B" is changed or cleared in Now mobile app? Any ideas how to solve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 11:00 PM
Hi @Elvin_Salim
This approach ensures that when the user changes or clears Field B, Field A will reset immediately on the form.
Steps:
-
Go to System Definition > Client Scripts.
-
Click on New and configure the following:
- Name: Clear Field A on Field B Change
- Table: [The relevant table for your form]
- Type: Mobile / Service Portal (since it's for the Now Mobile app)
- Active: Yes
- UI Type: All (or Mobile if specifically for Now Mobile)
-
Add this JavaScript code in the script section:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return; // Prevent script from running on initial load.
}
if (newValue == '' || newValue != oldValue) {
g_form.setValue('field_A', ''); // Clears Field A.
}
}
-
Trigger onChange Event:
- Field Name: field_B
- This script will run when Field B changes.
-
Save and test on the Now Mobile App.
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 11:28 PM
Hi @PrashantLearnIT ,
The script does not work on the mobile app. Could it be that which screen the fields are on in the mobile app?
BR,
Elvin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 12:56 AM
Hi @Elvin_Salim
Have you tried for UI Type as Mobile?
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.
********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect
Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 01:13 AM