Service Portal - set value of field in record producer

vzvinny
Kilo Explorer

Hey,

I'm trying to set the value of an input field in a record producer from the Service Portal widget's client or server script.

I have no problems using functions like g_form.setValue() on normal catalog items, but I'm lost with how to manipulate anything in a record producer.

Thanks

11 REPLIES 11

I did that, same result. Cheers Greg


jkc
Giga Expert

What you could do is actually send a CustomEvent back to the catalog item or record producer. 

What I have done is  create a catalog client script on my record producer. 
When a certain variable changes, I send a CustomEvent to the widget. 
Here I can do whatever I want with the new data (for me the sys_id of a business service) and once done, I can return data to the record producer by sending a CustomEvent from the widget to the same catalog client script 🙂

 

So.. 
onChange Catalog Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Fire the event when the field changes
CustomEvent.fire('chgOnChangeEventApplication', newValue);


//Listen for the event from the widget
CustomEvent.observe('chgHardwareList', changeField);

function changeField(hwList){
//Use g_form from client script as this is not possible from widget
g_form.setValue("hardware", hwList);
}
}

 

Client Script of the widget

//Listen for changes to the application field
CustomEvent.observe('chgOnChangeEventApplication', doThis);
//Run this function when event is triggered
function doThis(val){
c.application = val;
console.log("New Application/Business Service : " + val);
}

//From here you can then do whatever you have to with the data from the variable. 

 

//To send data back to the catalog client script, do this:
CustomEvent.fire('chgHardwareList', 'data_to_send');

//In my widget the functionality is called from a button with ng-click="c.submitHardware()"
c.submitHardware = function(){
CustomEvent.fire('chgHardwareList', hwList);
}