Comparing an object and string using js
![]()
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/> • 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/>";
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
![]()
Ralph Schoon (63.3k●3●36●46)
| 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:
|
![]()
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 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. ![]() 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.
|
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.