How to check/validate if a variable is read-only on service portal view?

aman_sharma_07
Tera Guru

Hi all!

 

I'm looking for a way to check if a variable is read-only on client side.

 

Any idea how that can be done?

 

Thanks!

1 ACCEPTED SOLUTION

@Ankur Bawiskar ,

Actually, it's a bit complicated logic which we have put in place.

 

We have a review feature for non-fulfillers, on the same form which is used to submit the request.

For your information, we have a client script (CS3) available for setting the variable values only(not making read-only), which triggers on change of var_a, other than that of var_e.

For review feature to work, we are only setting the value in var_a , so it can trigger the already developed client script.

 

So let me summarize this:

onLoad (CS1) -> set the value in var_a -> triggers the (CS3) -> sets the value in all variables, including var_e -> triggers the (CS2) -> sets the variables read-only, except var_e and clears the value.

 

Now coming to your suggestion;

  1. CS2 & CS3 can't be merged as it would dissolve the functionality of CS3, which is required independent for other use cases (where the variables shouldn't be read-only).

I'm thinking not to reuse this feature and re-build the functionality once again in the CS1 itself, and exclude var_e setting and resetting feature there.

 

Thanks for your help!
Regards,

Aman Sharma

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@aman_sharma_07 

what's your business requirement for this?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar !

thanks for your reply..

There are two client script in action:

1. Setting all the variables with values

2. Make all the variables read-only except one (let's say "var_e")

I need to clear the value from var_e which was set through client script 1, as well as make it editable manually after making them read-only using CS 2.

Trigger for the CS2 is onChange of the last variable being set, which is var_e (I used this approach to ensure that CS2 runs only when CS1 has done it's job).

Now when the user is inputting some value in var_e manually, it is getting cleared(as the script is triggering again).

 

I was trying to check if second last variable is read-only (which confirms the script has been executed previously), then it would return without doing anything.

 

PS: the CS1 has the logic reused for the other use cases as well, which I do not wanna alter.

 

Thanks for your attention and patient read!

@aman_sharma_07 

your 1st CS is setting value

then why not check in 2nd CS if the var_e has value inside it or not

Also your 1st CS is onLoad or onChange?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar ,

 

So, the first time when CS2 runs, var_e  still has value, being set by CS1.

So that condition would avoid the execution for the first time also!

 

The 1st CS is onChnage of a variable.

Kind regards..