We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Unable to set caller field readonly with setReadOnly()

SanjivaniLahane
Tera Contributor
function onLoad() {

    //g_form.setReadOnly("description", true);
    //alert(g_form.isReadOnly("description"));


    //g_form.setDisplay("short_description", false);
    g_form.setMandatory("caller_id",false);
    g_form.setValue("caller_id",g_user.userID);
    g_form.setReadOnly("caller_id", true);
    alert("done");
    //g_form.setReadOnly("u_caller", true);

}

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron

@SanjivaniLahane 

looks like you are trying to set default value in caller_id with logged in user

Why not use default value in dictionary as this -> gs.getUserID()

OR

Why not use display business rule on incident table and set it like this?

current.setValue('caller_id', gs.getUserID());

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Tanushree Maiti
Tera Patron

Hi @SanjivaniLahane 

 

Can you try with this execution order once:

 

g_form.setValue('caller_id', g_user.userID);

g_form.setMandatory('caller_id', false);

g_form.setReadOnly('caller_id', true);

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

yashkamde
Mega Sage

Hello @SanjivaniLahane ,

 

plz check for the other ui policies on caller _id field if there is any..

that can override your script.

 

also try using this fix :

function onLoad() {
    g_form.setValue("caller_id", g_user.userID);
    g_form.setMandatory("caller_id", false);
    g_form.setReadOnly("caller_id", true);
}

 

If my response helped mark as helpful and accept the solution.

svirkar420
Tera Guru

Hi @SanjivaniLahane   , First of all, check if there are any UI policies applied to the field with the same logic/condition cause if this is true then the UI policies will take precedence and client script will be overridden by UI policy.
The code that you have written is perfectly fine.


And if not this could you clarify the requirement more, like what are you trying to do exactly?

If this response helps you mark it as accepted solution and give it a thumbs up 👍. This help me and community to find answers quickly.

Best Regards,

Saurabh V.