Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Based on Alphabets and numbers we should want make that field Readonly

Sirri
Tera Guru

Hi All,

 

I have Requirement :

In catalog item there are some fields :

1)office (cmn_location)- Reference

2)Desk Loaction -single line text

 

we are getting data for Desk location when office is selected based on location there is a field(Default desk location) in location table:

After getting data from the location table:

1)If suppose  Desk location is contains all Alphabets it make ReadOnly.

   Location Name(office)                                         -      Default Desk Location

-Zurich                                                               -             Zurich

-Aix en Provence                                                  -            Aix-en-Provence

2)If suppose Desk location contains Numbers and alphabets then it not ReadOnly.

     Location Name(office)                                         -      Default Desk Location

-  Wilmslow                                                               -          CH/00/000

- New York (Avenue of the Americas)                     -           1251/00/000

-Birmingham                                                             -             67T/00/000

 

Please let us know how can I achieve this requirement.

Please provide code.

Please find the attached documents for your reference.

1 ACCEPTED SOLUTION

Sirri
Tera Guru

Hi All,

 

 I have written ui policy

I have mention the below conditions

      desk_location contains 0

or   desk_location contains 1 like the I have mention the upto 9

for these and in that  Run script I have written

 g_form.setReadOnly('desk_location',false);

else condition 

 g_form.setReadOnly('desk_location',true);

 

For more information please find the attached screen shots.

View solution in original post

3 REPLIES 3

Sandeep Rajput
Tera Patron
Tera Patron

@Sirri Please add an onChange client script on Desk location field as follows.

 

Screenshot 2023-11-21 at 11.51.48 PM.png

Here is the script for you.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    if (/^(\-?[a-zA-Z]*[^d\/]*)$/.test(newValue)) {
        g_form.setReadOnly('desk_location',false);
    } else {
        g_form.setReadOnly('desk_location',true);
    }
}

Hope this helps.

Hi @Sandeep Rajput ,

 

Thank you

I tried with this but always showing as read only always. As per my requirement I didn't change desk location.

Desk Location data is getting from office. Please read the requirement clearly.

Thank you so much.

Sirri
Tera Guru

Hi All,

 

 I have written ui policy

I have mention the below conditions

      desk_location contains 0

or   desk_location contains 1 like the I have mention the upto 9

for these and in that  Run script I have written

 g_form.setReadOnly('desk_location',false);

else condition 

 g_form.setReadOnly('desk_location',true);

 

For more information please find the attached screen shots.