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.

Make form read only in native view But editable in workspace

Prajwal G Vaish
Giga Guru

Hi Team,
In the form on Native view have created a button which leads to workspace to the same record. I require the form to be read only in native view but should be editable in workspace view.
Please let me know How can we achieve This.
Thank you.

1 ACCEPTED SOLUTION

Prajwal G Vaish
Giga Guru

I have used the Below Code and its working fine.

function onLoad() {
    //Type appropriate comment here, and begin script below
    var url = top.location.href; // getting the URL Link
    var pathname = new URL(url).pathname; // getting the Path workspace : now/risk/, Native :now/nav/ui/.
    pathname = pathname.split('/');
    var ur = pathname[2];// getting if its a workspace or native
    if ( ur == 'nav') {
        var fields = g_form.getEditableFields();
        for (var x = 0; x < fields.length; x++) {
            g_form.setReadOnly(fields[x], true);
        }
    }else{
        fields = g_form.getEditableFields();
        for ( x = 0; x < fields.length; x++) {
           g_form.setReadOnly(fields[x], false);
        }
    }
}

 

 

Regards,
Prajwal

View solution in original post

7 REPLIES 7

@Ankur Bawiskar 
I tried passing the View name to info message  showing undefined.
regards
Prajwal.

Prajwal G Vaish
Giga Guru

I have used the Below Code and its working fine.

function onLoad() {
    //Type appropriate comment here, and begin script below
    var url = top.location.href; // getting the URL Link
    var pathname = new URL(url).pathname; // getting the Path workspace : now/risk/, Native :now/nav/ui/.
    pathname = pathname.split('/');
    var ur = pathname[2];// getting if its a workspace or native
    if ( ur == 'nav') {
        var fields = g_form.getEditableFields();
        for (var x = 0; x < fields.length; x++) {
            g_form.setReadOnly(fields[x], true);
        }
    }else{
        fields = g_form.getEditableFields();
        for ( x = 0; x < fields.length; x++) {
           g_form.setReadOnly(fields[x], false);
        }
    }
}

 

 

Regards,
Prajwal

Thank you for Your Solution.