You are viewing limited content. For full access, please sign in.

Question

Question

SetBusinessProcessVariable from workflow not getting back to Forms process.

asked on February 6 Show version history

I have a sort of library system where users check things in and out. When they do this, I'm supposed to have the forms process print a ticket. 

The only way I could figure out how to do this was to return a variable called Print_TicketID from the workflow back to the form. This variable gets set with the ID of the new ticket I just created in my Sql Server database. I am passing a variable of this name to the workflow from the form. It's initially set to 0. 

I have "Automatically Load the next task if the same person is assigned to it" checked.

I have "Wait for the workflow to finish before proceeding" checked.

Then, in the On Completion Event, I am redirecting the process to go back to the same url, but I'm adding a querystring variable on the end of the url. Example:

beginningofurl/Forms/GageCheckout?Print_TicketID={/dataset/Print_TicketID}

It comes back to the form with Print_TicketID=0, (the original value) even though the workflow has dutifully returned the updated value. (See pics.) 

I am assuming it's going to the new url before the workflow has updated the variable? Why would it do this? What's the point of being able to set a variable if your forms process doesn't see it? 

The weird thing is this: I swear this USED to work. (This project stalled for a few months.) I swear this worked before!! What's changed?

 

Setting the variable to new ID.jpg
Here's what is returned from the workflow.jpg
Here's where I'm redirecting after workflow completes.jpg
0 0

Answer

SELECTED ANSWER
replied on February 6 Show version history

The workflow isn't running to update your form field value before the submission is complete, so the variable pulled is the one that was in the form when you started.  The next steps grab the number and insert it back to the form, but the Event Completion has already happened.  I think this post explains a workaround that could work for you: Any way to set a Form variable with workflow *before* the user sees the thank you page? - Laserfiche Answers

3 0

Replies

replied on February 6

In the Form Designer, confirm that the variable name of the field is "Print_TicketID".

0 0
replied on February 7

Thank you, Angela. That was the fix. Essentially, what you need to do is to set a field value BEFORE you submit the form. So, I have a StoredProcedure that gets a guid from SQL Server when the page loads. Then, I have a validation function that fires when the user clicks submit. Inside that validation function, I simply set the Print_TicketID = the guid value and submit the form. When the form comes back around, (after workflow), it now has that guid in the query string of the url. The first thing I do in the form (In the lookup complete function) is check for a value in that field. If there is one, I open up a hidden IFRAME and point it at the ticket url, handing it the guid. When the IFrame is ready it calls back to the main form that it's ready to be printed, so then I get the contents of the IFrame and print it. This sounds really complex but it's not that bad. I'm including the code here for anyone who wants it.

 

$(document).ready(function () {

  $('.Submit').click(function (e) { validateForm(e); });
  $('#q0').append("<div class='hidden' id='print_output'></div>");

  var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
  var printEvent = window[eventMethod];
  var messageEvent = eventMethod === "attachEvent" ? "onmessage" : "message";
  printEvent(messageEvent, function (e) {

    if (e.data === "printme" || e.message === "printme") {
      $("#myiframe").get(0).contentWindow.print();
      $('.print-ticket-id input').val(null);
    }
  });

  $(document).on('lookupcomplete', function (e) {
    //Field152 is the Print_TicketID field
	if (e.triggerId == 'Field152') { 
      if ($('#Field152').val()) {
        if ($('#Field152').val() != null) {
          print_receipt();
        }
      }
    }
  });
});

function print_receipt() {

  var domain = document.location.hostname;
  var receipt_url_root = "http://" + domain + "/Forms/";
  var receipt_url = "";

  if ($('.print-ticket-type-id input').val() == 1) {
    receipt_url = receipt_url_root + "PinGageReceipt?guid=" + $('.print-ticket-id input').val();
  }
  if ($('.print-ticket-type-id input').val() == 2) {
    receipt_url = receipt_url_root + "ThreadReceipt?guid=" + $('.print-ticket-id input').val();
  }

  if (should_print_receipt == true) {
    if (receipt_url != "") {
      loadiFrame(receipt_url);
      should_print_receipt == false;
      $('.print-ticket-id input').val(null).change();
    }
  }
}

function validateForm(e) {

  if (!$('.print-ticket-id input').val()) {
    //'.guid input' is the NEW guid that SQL server gave us when the form loaded
    //so that when we submit the form, our new guid will already be in there.
    $('.print-ticket-id input').val($('.guid input').val());
  }
  
  //do other stuff
  
 }
 
//THIS code is from the ticket. It calls back to the parent when it is ready.
$(document).ready(function() {
  $(document).on("onloadlookupfinished", function() {
    parent.postMessage("printme", "*");
  });
});

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.