Forum Discussion

GeorgeKhairalla's avatar
GeorgeKhairalla
Qrew Trainee
3 years ago

Save a record then revert it

Please bear with me as I try to explain the scenario. I'm looking for a couple things out of this:
1- Is the method I'm trying to implement the best way to do this, or is there a better one
2- I'm trying to correct the behavior of my current method. I'm almost there.

The goal is this:
- our provisioning team would edit a record (with the information that needs to change).
- They push a button (Send for Approval), and check the "Staging" button.
This button has the following code:

//Since [old.field] doesn't work here, we will remember the old values within the formula
var text OLDFIRSTNAME = [First Name];
var text OLDLASTNAME = [Last Name];
var number OLDRELATEDCOMPANYENROLLMENTFORM = [Related Company Enrollment Form];
var textlist OLDPRODUCTERP = [Product ERP];
var textlist OLDPRODUCTADDONAPP = [Product Add-On Apps];
var textlist OLDPRODUCTACCESSORYAPP = [Product Accessory Apps];
var text OLDPLATFORM = [Platform];
var text OLDEMAIL = [Email Address];
var text OLDPHONE = [Office Phone];

//Edit (and Save based on the "SaveBeforeNavigating" class) and switch the "Send Notification" field, to trigger the notification
var text SENDFORAPPROVAL = URLRoot() & "db/" & Dbid() &
"?a=API_EditRecord&rid=" & [Record ID#] &
"&_fid_138=true" &
"&_fid_140=true" &
"&apptoken=xxxxxxxxxxxxxxxx";

//Once the notification is sent, revert back all the values in the record to what they were before the edit, then redirect back to the parent record.
var text REVERT = URLRoot() & "db/" & Dbid() & "?a=API_EditRecord&rid=" & [Record ID#] &
"&_fid_6=" & $OLDFIRSTNAME &
"&_fid_7=" & $OLDLASTNAME &
"&_fid_61=" & $OLDRELATEDCOMPANYENROLLMENTFORM &
"&_fid_70=" & $OLDPRODUCTERP &
"&_fid_71=" & $OLDPRODUCTADDONAPP &
"&_fid_72=" & $OLDPRODUCTACCESSORYAPP &
"&_fid_73=" & $OLDPLATFORM &
"&_fid_9=" & $OLDEMAIL &
"&_fid_10=" & $OLDPHONE &
"&_fid_136=false" &
"&rdr=" & URLEncode(URLRoot() & "db/" & [_DBID_COMPANY_ENROLLMENT] & "?a=dr&rid=" & [Related Company Enrollment Form]);

//Put it all together
"<a class='Vibrant Success SaveBeforeNavigating' href='" & $SENDFORAPPROVAL & "&NextURL=" & URLEncode($REVERT) & "'>Send for Approval - Edit</a>"

I want this to Save the record. Which should create a "Notification" based on _fid_138 (Send Notification - Checkbox), which is now checked.
The next step would now use the "OLD" variables in the formula, to "reset" those fields back to their original values.

The end user now received a notification with a URL Formula for Approving that request, will require them to sign in, and write the record under their own credential, resulting in a fully audited entry.

The problem I'm having with the current setup, having "SaveBeforeNavigating", the changes don't get reverted, and I get an XML return stating that there were no errors, when i hit back on the browser, it doesn't revert the changes.
Looking at the resulting URL, I see that the "OLD" values are actually the "NEW" values. So, I guess they weren't retained through the save.

Any ideas what I could change to get this workflow to work? (If possible).
Could triggering a pipeline after the save work? and if so, is it possible to grab the previous values of the fields within the pipeline?

Alternatively, if I'm over complicating this in my head, if anyone might have any better way to accomplish this, I welcome the suggestions.

Thanks!

------------------------------
George Khairallah
CTO
gotomyerp, LLC
------------------------------

5 Replies

  • What is the ultimate goal?

    One user inputs what they want new values to be for a certain number of fields, but those new values do not populate until another user 'approves' the changes?

    ------------------------------
    Mike Tamoush
    ------------------------------
    • GeorgeKhairalla's avatar
      GeorgeKhairalla
      Qrew Trainee
      That's correct Mike.
      This would be in lieu of our staff having to retype in all the information in a record to send as a notification, our staff would instead just make the change, and save the record to send to the end user. Meanwhile the record would revert back to its original values, and would get written permanently only when the user approves it via their email button. (i.e: it would then be updated with their own Quickbase user, for auditing purposes)

      With that said, I think I got it resolved. I will do some more testing, but, in case someone else might have a similar scenario.
      What I did is I removed the second (Revert) part of the formula, and I created a Pipeline to trigger on the record if the field "Staging" is checked, (and if the modified date is within 5 minutes, for good measure)
      Then I used the values in there to get the previous value {{a.$prev.First Name}} , etc...

      This seems to have worked like a charm!
      Thanks!

      ------------------------------
      George Khairallah
      CTO
      gotomyerp, LLC
      ------------------------------
      • MikeTamoush's avatar
        MikeTamoush
        Qrew Commander
        You could also make a new form with new fields (named on the form the same as the old fields for the users ease). Call them Proposed New Field 1, Proposed New Field 2, etc.

        On your main form just have a button that says enter new proposed values. All that does is take you to a new form where they edit the values. Save and have something trigger the notification.

        If the values are approved, THAT button will change the values of the original.

        You could even have the first button click check a box that says something like 'Changes Pending', and then the approval button click uncheck that box. You can use that changes pending checkbox in a formula rich text or dynamic field to show on the main form when changes are pending.

        ------------------------------
        Mike Tamoush
        ------------------------------