It's all about the answers!

Ask a question

Comparing an object and string using js


Divya _ (254) | asked Mar 26, 10:59 a.m.
Hello team,

We have a calculated value script for adding a default value in Analysis Result attribute.
We now have created a script to compare if the default value and the value filled in the attribute by the user is same and display an error message.
Please find below the code snippet for your kind reference.
//
// STAGES_SAVE_ITEM_PRECONDITION
//
/* globals
        Logger
        MPConstants
        ErrorMessage
*/
var scriptName = "Validate Defect Analysis Result";
Logger.warn(MPConstants().logging.start + scriptName);

var currentWorkItem = Api.Operation.getCurrentWorkItem();
Logger.warn(currentWorkItem);
var currentWIProjectArea = currentWorkItem.getProjectArea();
var defectanalysisresult = "com.bosch.rtc.configuration.workitemtype.customattribute.analysisresult";
var currentWIAnalysisAttr = Api.Attributes.getAttributeById(currentWIProjectArea, defectanalysisresult);
Logger.warn(currentWIAnalysisAttr);

var currentWIAnalysisValue = Api.Attributes.getValueAsHtml(currentWorkItem, currentWIAnalysisAttr);
Logger.warn(currentWIAnalysisValue);


//var str2 = currentWIAnalysisValue.valueOf()

//var test = JSON.stringify(currentWIAnalysisValue);
//Logger.warn(typeof currentWIAnalysisValue);


var defectanalysis = "<b>Analyse Defect on the below aspect</b><br/>• is this a Defect/CR/Problem? If yes<br/>&nbsp;&nbsp; • is it necessary to trigger an alert notifications for this issue ?<br/>&nbsp;&nbsp; • is it necessary to trigger any urgent resolution actions?<br/><br/><br/><b>E.g.: describe the analysis results from below perspectives</b><br/>• impact on system<br/>• severity of issue<br/>• affected items (test benches, contracts, services, documentation, products)<br/>• affected parties<br/>• affected baselined artifacts<br/>• proposed solution<br/>• if needed proposed work-around or urgent resolutions/temporary fixes<br/>• if needed proposed preventive measures<br/><br/><br/>";

Logger.warn(defectanalysis);

//var str = new String(defectanalysis)

//flag = str2 == defectanalysis ? true : false;
//flag = currentWIAnalysisValue == str ? true : false;
//Logger.warn(currentWIAnalysisValue == defectanalysis);

flag = currentWIAnalysisValue == defectanalysis? true : false;
Logger.warn(flag); // The flag value returns as false though the values contained are same maybe because of the type of the variables

if (currentWIAnalysisValue == defectanalysis) {
    Logger.warn("inside if");
    var errorMessage = new ErrorMessage();
    errorMessage.append("Hellooo World!!");
    errorMessage.show();
    Logger.warn("End of if");
}

Logger.warn(MPConstants().logging.end + scriptName);

Could you please help us with your guidance and let us know if there is something wrong or missing here?

Thanks a lot in advance.

2 answers



permanent link
Ralph Schoon (63.3k33646) | answered Mar 26, 2:15 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Is this the result of a chatGPT prediction?? As far as I can tell:
  1. This is not a calculated value script. The syntax is completely wrong. The "API" is completely incorrect for attribute customization.  There is no Logger, there is no "API", there is no getCurrentWorkItem, getProjectArea, ErrorMessage etc. in the attribute customization JavaScript API.
  2. The attribute customization JavaScript API especially for calculated values does not support any UI interaction, where you can flash information in the UI.
Please find some introduction to attribute customization and related links and workshops here: https://rsjazz.wordpress.com/2022/11/25/ewm-attribute-customization-introduction/

permanent link
Divya _ (254) | answered Mar 27, 1:01 a.m.
Hello Ralph,

The script I've mentioned in my first post is not a Calculated value script.
Also, it is not a chatGPT prediction. We use a third party application called method park stages and we have written the script for comparison there.
Sorry for the confusion. Please find below the Calculated value script for the default value.

dojo.provide("com.bosch.rtc.js.client.defectanalysis.formal");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

/**
* @see https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Using_scripts_for_attribute_cust
* @see https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_Example
*/
(function() {
var doDebug = true;
var scriptname = "defectanalysis";
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;

dojo.declare("com.bosch.rtc.js.client.defectanalysis.formal", null, {

        getValue: function(attribute, workItem, configuration) {
        debug("Start");

var workflowType = workItem.getValue(WorkItemAttributes.TYPE);
debug("workflowType: " + workflowType);
        var workflowState = workItem.getValue(WorkItemAttributes.STATE);
debug("workflowState: " + workflowState);

//var inputText = workItem.getValue(attribute);

var defectanalysis = "<b>Analyse Defect on the below aspect</b><br>• is this a Defect/CR/Problem? If yes<br>   • is it necessary to trigger an alert notifications for this issue ?<br>   • is it necessary to trigger any urgent resolution actions?<br><br><br><b>E.g.: describe the analysis results from below perspectives</b><br>• impact on system<br>• severity of issue<br>• affected items (test benches, contracts, services, documentation, products)<br>• affected parties<br>• affected baselined artifacts<br>• proposed solution<br>• if needed proposed work-around or urgent resolutions/temporary fixes<br>• if needed proposed preventive measures<br><br><br>";
       
if(workflowType == "defect") {
//if(inputText !== "") return inputText;
if(workflowState == null) return defectanalysis;
if(workflowState == "") return defectanalysis;
else return inputText;
        }

return workItem.getValue(attribute);
    function debug(display){    
    if(doDebug){
        console.log(scriptname + " " + display);
    }
    }
    }
    });
})();



 

Comments
Ralph Schoon commented Mar 27, 2:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I suspected something like that after I answered. However, this is not a stages forum and I do not believe many practitioners here have any experience in it. I would suggest to work with Methodpark. 


Ralph Schoon commented Mar 27, 2:46 a.m. | edited Mar 27, 2:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Otherwise I don't know what should be wrong and what the expectation would be. Consider describing the problem. I can not make any sense of the question title, the script and what you actually want to ask.

One thing I see is the HTML Tags in the text to display. I am not sure if that will work, I had issues in the past when returning XML or HTML, because the converter escaped the tags.

I would suggest you debug your script. https://rsjazz.wordpress.com/2022/11/17/debugging-ewm-work-item-attribute-customization-javascript/  

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.