Making field on screen Read Only

I need to make a field on the screen read only when the screen is in Edit mode. I don't want to make the field read only in field level security as there are some procedures that will run that will update this field. I would like to do it on the screen configuration...or in the ASP page itself (if possible).

I have gone to the detail box on the screen through Administration --> Customization --> MyCustomEntity -->Screens

On the screen definition page, I entered the following in the OnChangeScript box...

if(CurrentUser.user_logon == "-1")
{
ReadOnly=false;
}
else
{
ReadOnly = true;
}

However, when I go to the screen and hit the change button...I can still change the field.

Am I doing this correctly? Based on the out come it does not appear so. Can someone please push me in the right direction?

Thank you!!

  • 0

    Hi Michele,

    What I understand from your above post is that you want to make a field read only based on the current logged in user. Here I assume that you are referring user logon field for checking purpose. I tried this code at my end and it works fine. SO could you please check whether the “-1” actually contains in the user logon field. Or else you can check the same with user id instead of user logon.

    Hope this helps!

    Regards,

    Dinesh

  • 0

    Just to add to what Dinesh has said, you would want to add that script on the 'Create script' rather than the 'On Change'.

  • 0

    No. Not On Load....

    Sorry to throw my hat into the ring...

    BUT

    Create scripts fire as the screen is assembled within the server before it is sent to the browser.

    A screen appears in the browser because of a request/response exchange.

    The browser sends the request for the screen. For example it may include the action code 200 for the company summary screen. The companyboxlong is retrieved from metadata. It has the fields comp_name, comp_type, comp_slaid etc. The create scripts are fired as the screen is loaded into the memory of the server (before it is sent to the browser) and the dll processes the create scripts of each field in turn (in the order in which they are listed in the field definition) and once the rules have been processed the HTML is generated and sent to the browser as the response.

  • 0

    Hi,

    A create script is run when the field is created on the server and sent to the client and therefore is a server side function that allows you to manipulate the field before it is rendered on screen.

    Due to this the COM object is available to be used (such as CRM.FindRecord) whereas the onchange script is client side only and therefore does not have access to the COM object directly, only standard browser objects used by (for example) javascript and jQuery. However, with the inclusion of the Client Side API this allows for AJAX style client side calls to the back end objects without the need to perform a post back (refresh of the page).

  • 0

    Thank you both for the response!

    Glad to know the code was correct :-). Toby, its is where I have it that is the problem. I moved it to the 'Create script' area and it works perfectly!! :-)

    I am still figuring the system out and since I was in "Edit" mode, putting it in 'On Change' made since to me. I did not think about putting it in 'Create Script' because I was thinking this was for when a New record was being added. I obviously need to go back and refresh my understanding of these fields. I am sure I am missing out on the true power of these fields and putting more in ASP pages than is necessary.

    Again...Thank you both!!

  • 0

    Indeed, its more like a preload. The code is used to prepare the field for loading to the screen. As its prepared on the server before being sent to the browser its a server side set of code hence why the server side objects are available.

  • 0

    Ahh...Thank you Daniel.

    so Create Script is like an "On Load"...

    Thank you for the explanation. I will be going back over these areas to make sure I understand them.

  • 0

    Thank you Jeff...this is very helpful in understanding..how it works and will help in understanding when to put code in this box

    I think I see it and why it is called "Create Script" ... my "page" is being "created".

    When placing code in this area (create script), I am adding to all the data that it is pulling through metadata to create that screen. The Create Script says "add me too".

    This is all before the "On Load" which would be used immediately AFTER the page has loaded.

    Thank you for the clarification!!