Crow Canyon Software Forum

Forum Navigation
Please or Register to create posts and topics.

Script action error

I have a few calcs to make on a form.
Some sub totals and a grant total. Rather than using many on change events to do the job I thought I would put it all in a script action and have the user press the script action to generate the totals.
I started off with a single calculation to see if it would work but it is failing straight away.
I get an error in the browser saying: Cannot read properties of null (reading 'get_item')

My script is

function(spContext, formContext, listColumnsInfo, currentItem, functionCallback) {
var TotalHours = 0
}

Thanks for sharing the script and requirement details above.

We believe you are using the script in the form event action. If so, please use below syntax to read the column value. Please refer sample article on this from https://www.crowcanyon.help/article/469/.

Read column value: var HourlyRate = _ccs_FormUI.fetchColumnValueUI("Child_x0020_Care_x0020_costs_x00");

To set the required value to the column, we can use return statement as shown below.
return sumChildCare;

I'm still missing something here I got the field to update by using column value mapping and then selecting value (instead of script) and then updating a column with the product() of 2 other columns. This worked fine except that it would always update the column with the value of the first amount before the second had been provided. For example of the user typed 50 into ColumnA then ColumnC would show 50 even though the user had not entered a value into columnB. It was the NULL value in columnB was being treated as a 1.

So, as I have a few calcs to do on this form I thought I do it all in one script as if(ColumnA && ColumnB) sounded like it would solve the issue mentioned above.
However I can't get the "script" version of "column value mapping to work at all. I can't even get it to alert() me the return value and I get no errors in the dev tools console.

I need (in the first instance) to be able the column called TotalChildCareAmount once I get that working I'll need to do likewise for another couple of fields - and then finally a grand total.
If I can get the first one working I should be good from there. I have checked and doubled checked the column internal names are correct.
It is set to execute on column value change and be applied in the new and edit forms

function() {
var CCperhour = _ccs_FormUI.fetchColumnValueUI("Child_x0020_Care_x0020_costs_x00");

 

 

Please make sure the variable CCperhour is consistent in the script(Please check the attachment). You can use the script below and let us know if it works for you.

var CCperhour = _ccs_FormUI.fetchColumnValueUI("Child_x0020_Care_x0020_costs_x00");
var numCChours = _ccs_FormUI.fetchColumnValueUI("Number_x0020_of_x0020_Child_x002");
if(CCperhour && numCChours) {
var sumChildCare = CCperhour * numCChours;
alert(sumChildCare);
return sumChildCare;

}

Uploaded files:
  • Screenshot-2025-01-21-182722.png

Thanks - a step closer. Now I can get the alert to show but after I dismiss the alert box the script button will process until the script ultimately times out. The dev tools gives me the error CCperHour is not defined (I don't see any such spelling in my script only CCperhour)

var CCperhour = _ccs_FormUI.fetchColumnValueUI("Child_x0020_Care_x0020_costs_x00");
var numCChours = _ccs_FormUI.fetchColumnValueUI("Number_x0020_of_x0020_Child_x002");
if(CCperhour && numCChours) {
var sumChildCare = CCperhour * numCChours;
alert(sumChildCare);
return sumChildCare;
CurrentItem.set_item(TotalChildCareAmount, sumChildCare);
}

The alert shows the value of sumChildCare but then the script errors out.
If I comment out //CurrentItem.set_item(TotalChildCareAmount, sumChildCare); it still fails so it seems to be the return statement that is generating the issue?

 

 

The timeout error is due to "functionCallback();" missing after the script is executed. If you want to update the value of the column, please use "formContext.setColumnControlValueByName("TotalChildCareAmount",sumChildCare);" instead of "CurrentItem.set_item(TotalChildCareAmount, sumChildCare);".

Please try the below script provided and let us know if it is working as expected.

var CCperhour = _ccs_FormUI.fetchColumnValueUI("Child_x0020_Care_x0020_costs_x00");
var numCChours = _ccs_FormUI.fetchColumnValueUI("Number_x0020_of_x0020_Child_x002");
if(CCperhour && numCChours) {
var sumChildCare = CCperhour * numCChours;
alert(sumChildCare);
formContext.setColumnControlValueByName("TotalChildCareAmount",sumChildCare);
functionCallback();
}
functionCallback();