How to make variable editor on RITEM read only on service portal

ritaaudi
Tera Contributor

Hi: I have the variable editor displayed on request items on the portal as such:

find_real_file.png

As you can see the variable editor fields are editable. I need to make them read only after the request is submitted. I tried the following client script on Both UI Type but it didn't seem to work:

function onLoad() {  

//Type appropriate comment here, and begin script below  

if(g_user.hasRole('admin')) {  

g_form.setVariablesReadOnly(false); //so that admins can edit the variables.  

} else {  

g_form.setVariablesReadOnly(true);  

}  

}  

Any ideas?

Thank you!

1 ACCEPTED SOLUTION

Hi Rita,
Firstly, sorry for the delay - I wasn't online yesterday.
So let's get into it!
1. You might also want to remove the 'Save' button from it - you can do this by simply commenting out the line in HTML with element <button>, or the whole footer div
2. Important remark is, that we will not be able to embed the widget at exactly the same place as the original variables were. It's because the whole form is being generated dynamically from the script. What we can do, is to place it at the very beginning, or very end - before the buttons.
So if we want to put it in the beginning, open your cloned form widget in editor and in HTML go somewhere about line 62, where you see <!-- form -->
right before it place these lines:


        <!-- Embedded variables -->


          <sp-widget widget="data.embedVariables"></sp-widget>


Screen Shot 2017-06-16 at 8.52.09 AM.png



If you want the variables after the form, place the lines right before the <!-- UI Action Links -->


3. Go to server script part and somewhere where the data objects are assigned, place this line


        data.embedVariables = $sp.getWidget('your_cloned_variables_widget');


Screen Shot 2017-06-16 at 8.52.36 AM.png


And this should work. Again, if you're using this page for more than just sc_req_item, you need to embed a condition so your variables are called only for the tables that can have variables. It could look like this:
HTML:



<!-- Embedded variables -->


          <div ng-if="data.hasVariables">


              <sp-widget widget="data.embedVariables"></sp-widget>


          </div>



Server Script: (almost at the end - maybe right before the line // Activity formatter is hardcoded to set specific options)


if (data.table == 'sc_req_item') {


  data.hasVariables = true;


        }



Hope this helps!


View solution in original post

12 REPLIES 12

Have you checked Applies on Requested items check box in your client script?


I think I found a workaround.


1. Remove the Variables from the form view (in the back end)


2. There is a widget called 'sp-variable-editor' which is exactly the same thing and we will be able to modify it in a way, that it becomes read-only. Clone this widget and add your cloned version to your page (page 'form' I believe).


3. Open the widget editor and edit your cloned version:


        - on server side script, search for about line 27, where the condition if starts => if (typeof values[f].......)


        - right below it insert a line of code data.sc_cat_item._fields[f].readonly = true;


Screen Shot 2017-06-14 at 5.27.28 PM.png


4. Now your variables should be read only.



ATTENTION:


If you're using this page for other records than just sc_req_item, then you should insert a condition around the whole widget, that it is displayed only if the table is sc_req_item. (I can help you to sort this out too)



Also, if you want to embed this into the form widget itself, you would need to modify the form widget and insert your newly created widget in between.



If you need help or more detailed explanation with any part of this, don't hesitate to contact me.




And if this info helps, I'll be happy if you mark it as helpful or give it a like


ritaaudi
Tera Contributor

Hi Kate: How can I embed the cloned 'sp-variable-editor' widget into the form widget or a clone of the form widget? Do you know? Thanks so much!


Hi: I went ahead and cloned the form widget and was hoping you can advise me to how to embed the   'sp-variable-editor' widget in it. Any idea? Thank you so much!


Hi Rita,
Firstly, sorry for the delay - I wasn't online yesterday.
So let's get into it!
1. You might also want to remove the 'Save' button from it - you can do this by simply commenting out the line in HTML with element <button>, or the whole footer div
2. Important remark is, that we will not be able to embed the widget at exactly the same place as the original variables were. It's because the whole form is being generated dynamically from the script. What we can do, is to place it at the very beginning, or very end - before the buttons.
So if we want to put it in the beginning, open your cloned form widget in editor and in HTML go somewhere about line 62, where you see <!-- form -->
right before it place these lines:


        <!-- Embedded variables -->


          <sp-widget widget="data.embedVariables"></sp-widget>


Screen Shot 2017-06-16 at 8.52.09 AM.png



If you want the variables after the form, place the lines right before the <!-- UI Action Links -->


3. Go to server script part and somewhere where the data objects are assigned, place this line


        data.embedVariables = $sp.getWidget('your_cloned_variables_widget');


Screen Shot 2017-06-16 at 8.52.36 AM.png


And this should work. Again, if you're using this page for more than just sc_req_item, you need to embed a condition so your variables are called only for the tables that can have variables. It could look like this:
HTML:



<!-- Embedded variables -->


          <div ng-if="data.hasVariables">


              <sp-widget widget="data.embedVariables"></sp-widget>


          </div>



Server Script: (almost at the end - maybe right before the line // Activity formatter is hardcoded to set specific options)


if (data.table == 'sc_req_item') {


  data.hasVariables = true;


        }



Hope this helps!