Solved

Client script wont trigger. Am I missing something?

  • 29 November 2021
  • 4 replies
  • 123 views

Userlevel 1
Badge +5

I am trying to trigger a script when a the end date is changed on the contracts screen. I tested the script itself and it works fine, but I cant get it to trigger when I want it to. The field I need to update is a custom field called Months Remaining and is linked to contracts.user_def5.

 

I linked the script to End Date.

 

Here is the client script:

var contractID = getControlValue('contract', 'contract_id');
var contractLength = getDBValue('1', contractID);
setControlValue('contract', 'user_def5', contractLength);
alert("done");

 

And the sql script it calls:

SELECT DATEDIFF(M,GETDATE(),CONTRACT.END_DT) FROM CONTRACT WHERE CONTRACT_ID = '{0}'

Are there other ways of triggering this?

icon

Best answer by Saranga Amaraweera 29 November 2021, 12:46

View original

4 replies

Userlevel 7
Badge +22

Hi @Fluffy ,

Have you tried adding the script as custom code on the click event in the save button?

 

Userlevel 1
Badge +5

Ok. It works thanks!

Userlevel 1
Badge +5

Is it possible to trigger it when a field changes? Perhaps only update the text on another field without saving to the databasis? 

Userlevel 7
Badge +22

@Fluffy ,

I doubt whether the textchanged event would work for this particular scenario as it does not behave as a standard text field (since it’s a dttm field). Otherwise it should work in the normal way. Have you tried this on the webclient with AddEditOpened screen event? But this will only work in the web client. Another option would be to set the script with an initial focus then triggering it with gotfocus event but I wonder whether that would work out well as per the requirement. Having the script on the save button captures the script on the click event but yes, that concern is there again, you need to click on the save button. 

Reply