Clear the field's value in the mobile app

Elvin_Salim
Tera Contributor

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?

4 REPLIES 4

PrashantLearnIT
Giga Sage

Hi @Elvin_Salim 

 

This approach ensures that when the user changes or clears Field B, Field A will reset immediately on the form.

Steps:

  1. Go to System Definition > Client Scripts.

  2. 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)
  3. 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
********************************************************************************************************

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

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
********************************************************************************************************

Hi @PrashantLearnIT ,

 

Yes, I did. Tested it as Mobile.

 

BR,

Elvin