What is wrong with following event ajax call ffrom form on chanhe od date field

What is wrong with following event ajax call ffrom form on chanhe od date field ?

window.FormAPI.evaluateServerSideExpression(function(fn){
          window.FormAPI.setValue("number41",fn);
},"=calworkdays(FormAPI.getValue("date1").id, FormAPI.getValue("date2").id])");

OriginalPostID-23033

OriginalPostID-23033

  Discussion posts and replies are publicly visible

  • There's a syntax error in the way you are passing the server-side expression. The evaluateServerSideExpression() function expects a string as it second parameter, however, if you need to get values from the form to be passed as parameters of the server-side expression you need to properly build your string. Right now you are literally passing the phrase: FormAPI.getValue("date1").id instead of the actual value of field. The reason is you made this statment part of the string instead of concatenating it to it. You also have a ] at the end which shouldn't be there.

    Here's the right version of your expression. I tested it and works as expected:

    FormAPI.evaluateServerSideExpression(function(e){window.FormAPI.setValue("number41",e);},"=calworkdays(" + FormAPI.getValue("date1").id + "," + FormAPI.getValue("date2").id +")");
  • Notice how I'm building the string of the server-side expression (which is the second parameter) using the + operator so the statement FormAPI.getValue("date1").id is evaluated before being added to the string "=calworkdays...." and click "Add Watch" you will see the mistake I mentioned before; the string is being evaluated literally due to the syntax error. Here's a link where I explain more how to use IE Developer Tools, see my last entry from Jan 27 forum.appian.com/.../2692

    This type of syntax errors can be easily found using IE Developer Tools JS Debugger. If you place a debugger; statement in the change event you can step through each line of code and if you select the =
  • One last thing to point out. The change event of a date is triggered until the second time a user picks a date. The change from blank to a new date is not considered a change in the date, therefore, the change event won't be triggered. In order to workaround the issue you can call the change event on the load event of the form for "date2":

    var dateID = 'date2';
    $('#date_date_' + dateID + '_valueDateSingle_fd_component_' + window.FormDesigner.runtimeNamespace + dateID +'_').trigger('change');

    This will allow the user to get the desired result in "number41", after fixing the syntax error I mentioned in my previous post, with a single click on a date from the date picker.
  • Hi Eduardo,
    I tested following rule on change :
    FormAPI.evaluateServerSideExpression(function(e){window.FormAPI.setValue("number41",e);},"=calworkdays(" + FormAPI.getValue("date1").id + "," + FormAPI.getValue("date2").id +")");

    and exception appear again.
    We have Appian version 6.6.0 installed and I copy plugin version 1.6.0
    and it seams that i have problem with Advanced Form Utility.
    Can you suggest me whats wrong ?
  • One more thing I started jboss as service and I see that the plugin is installed but I see two version for used command :
    09:11:37,270 INFO [STDOUT] 2012-02-03 09:11:37,270 [main] INFO com.appiancorp.plugins.LoggingPluginEventList
    ener - Successfully installed Plug-in 'Advanced Form Utility Support Functions' (com.appiancorp.forms.ajax) ve
    rsion 1.6.0.
    09:11:37,270 INFO [STDOUT] 2012-02-03 09:11:37,270 [main] INFO com.appiancorp.plugins.LoggingPluginEventList
    ener - Successfully installed Module 'ExpressionServlet' (com.appiancorp.forms.ajax:expressionServlet) versi
    on 1.6.0
    09:11:37,270 INFO [STDOUT] 2012-02-03 09:11:37,270 [main] INFO com.appiancorp.plugins.LoggingPluginEventList
    ener - Successfully installed Module 'ExpressionServlet2' (com.appiancorp.forms.ajax:expressionServlet2) ver
    sion 1.6.0

    should I used the second one ?
  • Can you export the form you are testing with and upload it to Forum? There are instructions on how to upload files at forum.appian.com/.../Uploading_a_Forum_Attachment Then let me know the directory where you place it so I can download it.
  • Sorry Eduardo I can not find the way to upload the export of the form. Can I sent you on a mail or something ?
  • Sorry, I forgot to mention that first step is to use the forum post of this component to get access to the upload document functionality. Navigate to this post: forum.appian.com/.../4539 and click on "Attachments". Once you see the "Attachments" window click "Add Attachments" and from there follow the instructions from forum.appian.com/.../Uploading_a_Forum_Attachment
  • Hi Eduardo I uploaded it on following location : Default Community-->Temporally Doc KC -->Temporally Doc -->Advance_Forms. Tell me if you need anything else from me.
    Best Regards,Natasa
  • Thank you! Here are a couple things to fix:

    1. With this new version of the plug-in, you don't have to include the Advanced Forms JS library in your form's Custom JS field. You only have to add this to your load event:

    importScript('/plugins/servlet/FormsExt.js');

    2. The id of your number component, at least in your example, is number33 not number41.

    3. This is a simplified version of your example: forum.appian.com/.../36837