Creating an Array of Calculated Attribute Values for display in a single Label Extension

When working with situations where there are lots of calculated attributes that are generated, for example, from a simple set of data entry items (think of entering 3 or 4 attribute values that you then use to calculate lots of things – the user gives you their date of birth, you calculate their age, they give you their last name and you capitalize it and so on) it is often useful to group the calculated attributes together for several reasons, and a Label Extension is one way to achieve that:

  1. Designing a screen to display so many input and calculated attributes can get very time consuming.
  2. Displaying very large amounts of information on a Screen, especially inside an Entity Collection, can slow the screen display down considerably
  3. If the calculated attribute values belong together, then display them together

So one answer is to create a single, concatenated calculated attribute and then use a Label Extension to display the resulting array as a single composite attribute. So for example:

And if that is our little “array” we can turn it into a real array in the Label Extension:
/*  Generated by the intelligent-advisor.com Website Code Generator 05/05/2022 09:07
 Boilerplate Code of Custom Label Extension for Intelligent Advisor fka Policy Automation
 I will remember this is for demonstration purposes only. 
*/
OraclePolicyAutomation.AddExtension({
    customLabel: function(control, interview) {
        if (control.getProperty("type") == "splitter") {
            return {
                mount: function(el) {
                    var div_parent = document.createElement("div");
                    div_parent.id = "customSplitterLabel_parent";
                    var div = document.createElement("div");
                    div.id = "customSplitterLabel";
					var arrayofvalues = interview.getValue("array").split("!" )
					var finaltext =""
					var interimtext;
					for (let i = 0; i < arrayofvalues.length; i++) {
						interimtext = "Calculated Value #" + i + " : " + arrayofvalues[i] + "<BR>"
						finaltext += interimtext;
}
                    div.innerHTML = finaltext;
                    div_parent.appendChild(div);
                    el.appendChild(div_parent);
                },
                update: function(el) {},
                unmount: function(el) {}
            }
        }
    }
})

So the output looks like this video, which demonstrates the capture of the data and the display of the result in the Label Extension. The nice thing about this technique is of course you can take it much further:

  1. You can of course add as many different attributes into your composite label as you wish, it will spit them out correctly.

But this example means mixing technical and business rules in Word. You can remove the text rule from the Word document if you wish and add it to the JavaScript file, to separate the technical stuff from the business rules. So in the case shown, the Word would now look like this:

And the JavaScript might look a bit like this, simplified for the demonstration:
OraclePolicyAutomation.AddExtension({
	customLabel: function (control, interview) {
		if (control.getProperty("type") == "splitter") {
			return {
				mount: function (el) {
					// remember to create opm.extension.data.json file with attribute names in it
					// and load the values using interview.getExtensionData() if they are not being displayed on this Screen
					interview.getExtensionData();
					var div_parent = document.createElement("div");
					div_parent.id = "customSplitterLabel_parent";
					var div = document.createElement("div");
					div.id = "customSplitterLabel";
					// build the composite
					var composite = interview.getValue("firstlength") + "!" + interview.getValue("age").toString() + "!" + interview.getValue("upper")
						// create array
						var arrayofvalues = composite.split("!")
						var finaltext = ""
						var interimtext;
					// iterate
					for (let i = 0; i < arrayofvalues.length; i++) {
						interimtext = "Calculated Value #" + i + " : " + arrayofvalues[i] + "<BR>"
							finaltext += interimtext;
					}
					// display both
					div.innerHTML = composite + "<BR><BR>" + finaltext;
					div_parent.appendChild(div);
					el.appendChild(div_parent);
				},
				update: function (el) {},
				unmount: function (el) {}
			}
		}
	}
})

This is not the only way to do this, and small numbers of calculated attributes will not warrant such an approach but it seemed interesting enough to post here. The official documentation can, as always, be found here.

video
play-sharp-fill

Have a great day!

You might also be interested in these articles:

Author: Richard Napier

After 8 years in case management and ERP software roles, Richard Napier joined Siebel Systems in 1999 and took up the role of managing the nascent Siebel University in Southern Europe. He subsequently was Director of Business Development and Education for InFact Group (now part of Business & Decisions) for 8 years. He now runs Intelligent Advisor IT Consulting OÜ. Owner of intelligent-advisor.com, he also is Co-Founder of the Siebel Hub.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Intelligent Advisor IT Consulting Serving Customers Worldwide
Hide picture