cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Setting textbox value to calculated field output

Jump to solution

Hi

I have a calculated field with formula

If(MRMapType=="SSCC Report Map","ANNEXURE A:","")

I would like the output of this calculated field to appear in a textbox on the form

For example

The Textbox will display ANNEXURE A if the MRMapType is equal to 'SSCC Report Map'

I thought that setting the Connected to field in the calculated field would work but not so.

Does anyone know how this might be done?

Cheers

Laurie

Labels: (2)
0 Kudos
Reply
13 Replies
Workflow Hero

Re: Setting textbox value to calculated field output

Jump to solution

Try the below workaround (this worked for me):

  1. Set 'Store Client ID in JavaScript variable' for the Calculated and Textbox field controls
  2. In Custom Javascript of the Form, on document click event check if Calculated field value is not same as Textbox field value to assign Calculated field value to Textbox

Reply
Workflow Hero

Re: Setting textbox value to calculated field output

Jump to solution

Hi Laurie,

What do you want to do with the text box?  Do you simply want the calculated value to be saved back to your list or did you want the text box to be populated with that value and still be editable?

Cheers,

Chris

0 Kudos
Reply
Workflow Hero

Re: Setting textbox value to calculated field output

Jump to solution

That does not work here

I did exactly as you told:

1. Set 'Store Client ID in JavaScript variable' for the Calculated and Textbox field controls:

2. Put this code into Custom Javascript of the form:

NWF$(document).ready(function() {
NWF$(document).click(funktion() {
if(NWF$("#"+ calField).val() != NWS$("#"+ txtField).val())
NWS$("#"+ txtField).val(NWS$("#"+ calField).val());
});
});

Chris Ben‌: yes, I want to have a text box populated with a (dynamic) value and it should be editable.

BTW: that is something I would like to have as a standard. If you think so too, please vote for it here:

https://nintex.uservoice.com/forums/229406-2-nintex-forms-for-sharepoint/suggestions/18838480-use-a-... 

Reply
Workflow Hero

Re: Setting textbox value to calculated field output

Jump to solution

Hi

I tried Chaitra's solution and while it did put the value in the textbox when I clicked on another textbox on the form the event fired again causing any text after ANNEXURE to be deleted and replaced with  ANNEXURE A:

Not what I wanted but this is how the code would work I think.

To answer Chris's question I want the text box to be populated with that value ANNEXURE A and still be editable.

The users will add further text so the final text might be  ANNEXURE A: Yuendumu

Cheers

Laurie

Reply
Workflow Hero

Re: Setting textbox value to calculated field output

Jump to solution

So is it one time onload of the form you require the Calculated field value in TextBox, it can be done using the below script:

NWF.FormFiller.Events.RegisterAfterReady(function () {
NWF$(document).ready(function() {

var calculateControl = document.getElementById(calField);
var textboxControl = document.getElementById(txtField);
textboxControl.value = calculateControl.value;
});
});

Reply
Workflow Hero

Re: Setting textbox value to calculated field output

Jump to solution

That did not work here. Reason: script is faster than the calculated value calculation.

I built in a delay, and with that it works:

NWF.FormFiller.Events.RegisterAfterReady(function () { NWF$(document).ready(function() {function sleep(ms) {return new Promise(resolve => setTimeout(resolve, ms));} async function demo() { await sleep(500);textboxControl.value = calculateControl.value;  }
var calculateControl = document.getElementById(calField); var textboxControl = document.getElementById(txtField);
if (calculateControl.value===''){demo()}; }); });

Cheers

mai-kel

Reply
Workflow Hero

Re: Setting textbox value to calculated field output

Jump to solution

look here for one of possible solutions  

I believe you would find several other examples if you searched the forum

0 Kudos
Reply
Workflow Hero

Re: Setting textbox value to calculated field output

Jump to solution

Hi

Thanks for all the help.

The calculated value would be written to the textbox on the change of a drop down, not on a form load or a general

The link provided by Marian talks about what I want but does not include the code for the following

"fire a change() method on control like a dropdown then write the value from the calculated value into my text box" 

In my case the dropdown is called MRMapType. I don't know javascript syntax (obviously) but I think code that would do the above would do the trick

0 Kudos
Reply
Workflow Hero

Re: Setting textbox value to calculated field output

Jump to solution

The link provided by Marian talks about what I want but does not include the code for the following

"fire a change() method on control like a dropdown then write the value from the calculated value into my text box" 

if I understood your situation correctly you not do need any dropdown change handler.

since your calculated value control's formula depends on dropdown value (MRMapType), it will be automatically recalculated with every change of the dropdown. and if the formula contains call to a javascript function, the function will be invoked as well.

so, what's provided on linked discussion should be really all what you need.

Reply