How to make custom date field in RTC read- only after user enters a date in it and saves workitem?
We have RTC 5.0.2 with custom Defect workflow. There is a custom date field "Fix Turnover date" with the default value as NONE. We need to make this field required as soon as user enters a date there and clicks Save. I created a custom script from IBM sample and it made the field as read only for all the preexisting defects with date in the field (which is correct). I added Read Only attribute for Condition for Save action for Everybody under operational behavior. I tried to create a new defect, saved it and then populated Fix turnover date field and clicked Save. The error message is displayed "Attribute 'Fix Turnover Date' is not modifiable. The 'Fix Turnover Date' attribute is not modifiable". Then I enter an Alert line in the code to show me how system reads the value in the field. With the Alert line in the code functionality works as it supposed to (meaning it makes the field read-only when I enter a date and then click Save). However, if I comment out Alert link - I am back to having an error message. Is there issue with the script ? Pasting script below. Any help is really appreciated.
dojo.provide("org.condition.readonly");
|
3 answers
The obvious problem with the script is that it does not return a value when fixTurnoverDate is null.
Comments
Yelena Smelyanskaya
commented Jun 08 '17, 9:09 a.m.
Thank you. We tried that too and had the same outcome. The strange thing is that code works only if alert line is commented in and we click on OK from alert message box during execution - then it greys out the field as we needed (after clicking Save on the page). If alert line is commented out - when we click Save it sows red error on a page after we click save that field is not modifiable. It seems it makes it read only somewhere on a back end before we click Save for some reason.
Yelena Smelyanskaya
commented Jun 08 '17, 9:12 a.m.
And one correction to my question - we need to make this field read -only after user enters a date and clicks Save (not required, as I originally mentioned by mistake).
Ralph Schoon
commented Jun 08 '17, 9:34 a.m.
| edited Jun 09 '17, 9:55 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
The alert does not mean anything and you must not use it.
Conditions have to return true or false. the condition itself does not make anything read only or mandatory. You need to configure operational behavior in addition to the condition.
Conditions have access to the selected action (to change the state) and you have to make sure you understand the state you are in and how to access it.
See https://jazz.net/wiki/bin/view/Main/AttributeCustomization , https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Conditions,
https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Accessing_an_item_s_Status_attri , https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript
I overlooked something - conditions can not see that a attribute value is changing - see my second answer.
While testing close the work item/browser or use CTRL+F5 to make sure to reload the work item with the changes.
Ideally start with a condition that simply returns true or false so you know something works.
Yelena Smelyanskaya
commented Jun 09 '17, 12:51 a.m.
Thank you. I did create operational behavior for Save action for "everybody" and added Read-Only attribute for condition. I understand that alert really doesn't mean anything, I just used it to see how it sees the value (for debug purposes only). But when alert is in place - everything works fine (meaning that logic is correct). But if alert is commented out - we see the error that field is not modifiable after clicking Save (on any state). It looks like that system greys field out on a backend before Save request is completed (like something is not synchronized).
Donald Nong
commented Jun 09 '17, 1:07 a.m.
Not quite sure why the alert would work for you, as I can only imagine it breaks the script. You set the precondition for Operational Behavior "Save Work Item (server)", right? Then the script is expected to run on the server - where do you expect the alert window to appear? For debugging purpose, use console.log().
Your script works perfect. It makes the work item attribute read only, once it has a value. Since there is no more data than the attribute itself, it can not decide e.g that the previous value was not set.
showing 5 of 7
show 2 more comments
|
Ralph Schoon (63.5k●3●36●46)
| answered Jun 09 '17, 2:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Jun 09 '17, 3:01 a.m. For all I know, conditions can not detect the previous value of an attribute and the current value of the attribute. they only see the current value. As soon as some value is set, it is set for the script. So unless there is an additional information you can use (e.g. a state) to determine when your script should return true, you will not be able to do this. E.g. the best you can achieve is once you actually enter a date, the condition will actually see the date and return true and the attribute will show read-only. Comments I have seen people using hidden attributes to detect the set/change in JavaScript which I consider quite ugly.
Another option would be an advisor. It can not make the attribute read only, but it can access the value before the save and the value that is going to be saved and prevent a save if y value gets changed which should not. E.g. you could detect an unset date and allow saving a new value or detect a date/time and prevent changing it.
|
Thanks to all for help. I found an answer here https://stackoverflow.com/a/5706881
It appeared that page was not ready yet and it worked with alert because alert provided additional timing for the request to go through.
if(fixTurnoverDate != null) { if ( document.readyState !== 'complete' ) return; clearInterval( tid ); }, 100 ); return true; }
Comments I am not sure if document.readyState is available if the condition runs in the context of an Eclipse client. Not sure if that is even of interest, but if you have people using other clients, you might want to make sure that the scripts work in these clients.
Yelena Smelyanskaya
commented Jun 13 '17, 12:22 p.m.
Thank you Ralph. General users are using RTC application through the browser only and RTC client is used for some administration or customization implementation only. Did you mean that if somebody would try to update defect by using RTC client functionality might not work? If yes, then this scenario is not applicable for our usage model. Could you please clarify? Thank you again for your help.
Ralph Schoon
commented Jun 13 '17, 3:08 p.m.
| edited Jun 13 '17, 3:09 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
TRY IT OUT WITH THE RTC ECLIPSE CLIENT IF YOU USE IT AND MAKE SURE THE JAVASCRIPT YOU USE WORKS WITH THAT CLIENT.
Yelena Smelyanskaya
commented Jun 15 '17, 12:56 a.m.
We do not use RTC client to create work items. We use browser only (from users machines). RTC client is installed on the server and is used only to set some customizations as the one I was having problems with. Solution with the "document.readyState !== 'complete' fixed the issue and attributes becomes read only in a browser. When I had "alert" in the code initially it probably was giving some additional time for the Save request to complete. |
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.