It's all about the answers!

Ask a question

RTC Calculated Script Clarification


RTC User Prime (213) | asked Mar 28 '23, 4:09 a.m.
edited Mar 28 '23, 9:46 a.m.

 Is it possible to have RTC Calculated Script for the below using enumerations. where Factor A to Factor H are having specific values, where in the below calculation is done and the result would be a Read-only Enumeration on a specific state.


Factors
Enumeration Attribute for Factor A Yes (25) No (0)
Enumeration Attribute for Factor B Yes (25) No (0)
Enumeration Attribute for Factor C Yes (25) No (0)
Enumeration Attribute for Factor D Yes (5) No (0)
Enumeration Attribute for Factor E Yes (5) No (0)
Enumeration Attribute for Factor F Yes (5) No (0)
Enumeration Attribute for Factor G Yes (5) No (0)
Enumeration Attribute for Factor H Yes (5) No (0)

Enumeration Attribute for Calculating Total = A B
If the evaluation result is higher than 50 , the result is A.  If the evaluation result is less than 50 , the result is B.


5 answers



permanent link
Ralph Schoon (63.1k33646) | answered Mar 28 '23, 4:53 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 The question is barely readable and does not make any sense to me.  It should be easy enough to create a presentation and a pseudo algorithm that explains what you want. 

Regardless, it is possible to create a calculated value for an enumeration attribute. The editor presentation for that attribute can be read only. The calculated value can access other attributes and operate on their values. 


Comments
RTC User Prime commented Mar 28 '23, 9:47 a.m.

Updated the clarification by having them aligned.


 


Ralph Schoon commented Mar 28 '23, 10:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I stand by my answer. You can compare enumeration values for multiple attributes, do the calculation above and return the enumeration value based on the comparison from the choice A and B. 


RTC User Prime commented Mar 29 '23, 6:34 a.m.


permanent link
RTC User Prime (213) | answered Mar 29 '23, 6:34 a.m.
 The below script is not working. Please let me know if anything is wrong

dojo.provide("com.ibm.alinma.rtc.calculatedScript.evaluationresult");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function () 
{
dojo.declare("com.ibm.alinma.rtc.calculatedScript.evaluationresult", null, 
{
getValue: function (attribute, workItem, configuration) 
{
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var A = workItem.getLabel("com.ibm.team.workitem.initiative.customattribute.samplePA.A");
var B = workItem.getLabel("com.ibm.team.workitem.initiative.customattribute.samplePA.B");
var C = workItem.getLabel("com.ibm.team.workitem.initiative.customattribute.samplePA.C");
var D = workItem.getLabel("com.ibm.team.workitem.initiative.customattribute.samplePA.D");
var E = workItem.getLabel("com.ibm.team.workitem.initiative.customattribute.samplePA.E");
var F = workItem.getLabel("com.ibm.team.workitem.initiative.customattribute.samplePA.F");
var G = workItem.getLabel("com.ibm.team.workitem.initiative.customattribute.samplePA.G");
var H = workItem.getLabel("com.ibm.team.workitem.initiative.customattribute.samplePA.H");
var Result = workItem.getLabel("com.ibm.team.workitem.initiative.customattribute.samplePA.EvaluationResult")
var total = 0;

if (A === "Yes" ) 
{
A_Value = 25;

else if (A === "No" || A === "Unassigned") 
{
A_Value = 0;
}

if (B === "Yes" ) 
{
B_Value = 25;

else if (B === "No" || B === "Unassigned") 
{
B_Value = 0;
}

if (C === "Yes" ) 
{
C_Value = 25;

else if (C === "No" || C === "Unassigned") 
{
C_Value = 0;
}
if (D === "Yes" ) 
{
D_Value = 25;

else if (D === "No" || D === "Unassigned") 
{
D_Value = 0;
}
if (E === "Yes" ) 
{
E_Value = 5;

else if (E === "No" || E === "Unassigned") 
{
E_Value = 0;
}
if (F === "Yes" ) 
{
F_Value = 5;

else if (F === "No" || F === "Unassigned") 
{
F_Value = 0;
}
if (G === "Yes" ) 
{
G_Value = 5;

else if (G === "No" || G === "Unassigned") 
{
G_Value = 0;
}
if (H === "Yes" ) 
{
H_Value = 5;

else if (H === "No" || H === "Unassigned") 
{
H_Value = 0;
}
// Criteria Contribution Weights:
// 1.       A            25%
// 2.       B  25%
// 3.       C  25%
// 4.       D 5%
// 5.       E  5%
// 6.       F 5%
// 7.      G  5%
// 8.     H   5%
// TOTAL               100%
var totalPriority = (A_Value + B_Value + C_Value + D_Value  + E_Value + F_Value + G_Value + H_Value);

if (totalPriority >= 50 ) 
{
EvaluationResult = "DropeDown1";

else if (totalPriority < 50) 
{
EvaluationResult = "DropeDown2";
}
}
});
})(); 


permanent link
Ralph Schoon (63.1k33646) | answered Mar 29 '23, 6:39 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Mar 30 '23, 3:41 a.m.

  I would suggest you carefully read https://rsjazz.wordpress.com/2022/11/25/ewm-attribute-customization-introduction/ and maybe look into the documentation, workshop(s) and examples.


In addition to that, I would like to suggest to you that if a function was to return a value, you should probably return a value in one of the last statements at the end of your function. I would suggest you consider debugging your script ( https://rsjazz.wordpress.com/2022/11/17/debugging-ewm-work-item-attribute-customization-javascript/ ) link to be found in the post mentioned above.


permanent link
RTC User Prime (213) | answered Apr 03 '23, 3:27 a.m.

 Thanks Ralph 


With the links provided, I was able to crack the script by using the debugging method as the ready only enumerated field is getting updated based on the selection. The only issue is that the logic seem to be missing as I suspect the way the addition and updation is not correct. Can you help me on that part alone ?

Written Logic

var total = A + B + C + D + E + F + G + H;


if (total >= 50 ) 
{
EvaluationResult = "AA";

else if (totalPriority < 50) 
{
EvaluationResult = "BB";
}
return EvaluationResult;
}
When I select A B C D E F G H as Yes Yes No No No No No No in Sequence its working
When I select C D E H A G F B as No No No Yes No No No Yes in Random its not working.

Anything to be added to the logic to have the calculation done irrespective of the sequence of selection ?


Comments
Ralph Schoon commented Apr 03 '23, 5:13 a.m. | edited Apr 03 '23, 5:24 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 There is not enough information to do a lot. Issue: 

  1. You use total and totalPriority to compare. The latter variable does not exist.
  2. Make sure that the value of the attribute you calculate here has all other attributes as dependency.
I would write the code like this

var result = "BB";
if(total>= 50){
   result = "AA";
}
return result;


permanent link
RTC User Prime (213) | answered Apr 03 '23, 6:17 a.m.

There is a small mistake as "total" and "totalPriority" are the only comparison criteria


Below is the sample code
var A = 0;
    
.
    
var H = 0;
    
var total = 0;
var EvaluationResult = 0; 
if (Req1 === "Yes" ) 
            {
                A = 25;
            } 
            else if (Req1 === "No" || Req1 === "Unassigned") 
{ A = 0; }
.
        
.
        
.
        
.
        
if (Req8 === "Yes" ) 
            {
                H = 5;
            } 
            else if (Req8 === "No" || Req8 === "Unassigned") 
{ H = 0; }
var total = A + B + C + D + E + F + G + H;


if (total >= 50 ) 
{
EvaluationResult = "AA";

else if (total < 50) 
{
EvaluationResult = "BB";
}
return EvaluationResult;

Your answer


Register or to post 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.