how to call a ui macro from on change client script which(UI macro) should create dynamic input text fields based on input form variable ?

naveen_snow
Kilo Contributor

Still there are many questions unanswered even after searching community   ?

1. How can we call UI macro from client script? can any one help me with syntax ?

(as said in one community post .. calling required function in ui macro but this is not actaully working)

2. Is there a posibility to create dynamic input fields based on   any input of a catalog form , if so how can we do that. i.e lets say if i want to create multiple users using catalog request , i will provide number of users to add.Let's Say 6 so the macro should dynamically create a from which should have 6 fields   !..

How can we achieve this scenario   ??

7 REPLIES 7

Hi Ankur,

 

Do you know how do i call function in the onLoad Client Script from a macro. I have button that is showing in the RITM, on click of that button i want the function in onLoad Script to trigger and do calculation from a column Multi row variable set and update a field in the catalog item.

 

UI Macro

<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


<input id="calc" type="button" value="Calculate Total Area" onclick="xyz();" />
<script>

function xyz(){
javascript:alert('Hi');

calcTotal();
}


</script>


</j:jelly>

 

 

onLoad Script

 

function onLoad() {
//Type appropriate comment here, and begin script below

}
function calcTotal() {
var mrvs = this.my_g_form.getValue('area_allocations');

var objList = JSON.parse(mrvs);
for (var i = 0; i < objList.length; i++) {
calculatedArea += parseFloat(objList[i].allocated_area);
}

g_form.setValue('total_allocated', calculatedArea);

}

 

find_real_file.png

 

Hi,

inside the UI macro function you can get the MRVS row as json string using g_form.getValue('mrvsVariableName')

Parse it and then add up and then use g_form to set the other variable

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank Ankur.That worked.