Onload client script to make filed readonly

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2018 11:47 PM
I wrote client script to make some fields readonly if it is mobile view.
When i tested it on desktop by setting the mobile view it is working fine but when i tested it after connecting to the instance on mobile(handset). it is still showing as editable.
i used the below script:-
function onLoad() {
//Type appropriate comment here, and begin script below
var phase = g_form.getValue('u_phases'); //Fetching type of change
if(getView('mobile')){ //setting below fields as readonly only for mobile view
g_form.setReadonly('number',true);
g_form.setReadonly('type',true);
g_form.setReadonly('risk',true);
g_form.setReadonly('short_description',true);
g_form.setReadonly('start_date',true);
g_form.setReadonly('end_date',true);
g_form.setReadonly('u_uat_sign_off',true);
g_form.setReadonly('description',true);
}
}
Its working on desktop in mobile view but not after connecting instance on handset. Below is the screenshot
- Labels:
-
Field Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2018 11:54 PM
Hi Ashutosh,
In your script i don't see any code to make below fields Readonly.
1.Maker
2.Checker
3.Tester
Try as below,
function onLoad() {
//Type appropriate comment here, and begin script below
var phase = g_form.getValue('u_phases'); //Fetching type of change
if(getView('mobile')){ //setting below fields as readonly only for mobile view
g_form.setReadonly('number',true);
g_form.setReadonly('type',true);
g_form.setReadonly('risk',true);
g_form.setReadonly('short_description',true);
g_form.setReadonly('start_date',true);
g_form.setReadonly('end_date',true);
g_form.setReadonly('u_uat_sign_off',true);
g_form.setReadonly('description',true);
g_form.setReadonly('u_maker',true);
g_form.setReadonly('u_checker',true);
g_form.setReadonly('u_tester',true);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 12:06 AM
I don't want to make below fields readonly
1.Maker
2.Checker
3.Tester
It is working fine in the screenshot i pasted above. My concern is that it is not working when i am looking up the same change request on mobile phone.
Since i have given the condition
if(getView('mobile')){ //setting below fields as readonly only for mobile view
so it should work with mobile view.
Did i missed something?
Thanks...!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 12:08 AM
Try to get the view first and then compare it in if condition. I have provided the code below. Plesase check it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2018 12:09 AM
Try with the below code,
function onLoad() {
//Type appropriate comment here, and begin script below
var phase = g_form.getValue('u_phases'); //Fetching type of change
var view = getView();
if(view =='mobile'){ //setting below fields as readonly only for mobile view
g_form.setReadonly('number',true);
g_form.setReadonly('type',true);
g_form.setReadonly('risk',true);
g_form.setReadonly('short_description',true);
g_form.setReadonly('start_date',true);
g_form.setReadonly('end_date',true);
g_form.setReadonly('u_uat_sign_off',true);
g_form.setReadonly('description',true);
}
}