Saving data in Forms Manager as a form post

The data is written to the Forms Manager using the avantgo.submissionManager object. See PODSSubmissionMgr object.

To save data in Forms Manager as a form post
  1. Access the submissionManager.

  2. Look through the forms manager for a previous submission.

  3. Test the form title to is if it is the correct form.

  4. If there is a previous form for this record, update the submission and return.

    Code for steps 1 – 4:

    var subMgr = avantgo.submissionManager;
    
    // First look to see if we have edited this 
    // user's info before 
    var cnt = subMgr.length; 
    while(cnt--) { 
        submission = subMgr[cnt];
    
        // Handle the deleted submissions 
        if(submission == null) 
            continue;
    
        // this is not the one we are looking for 
        if((submission.title != document.updateForm.empId.value)) 
            continue;
    
        element = 
            subMgr.submissionElementForName("lastName"); 
        element.value = 
            document.updateForm.lastName.value; 
        element = 
            subMgr.submissionElementForName("firstName"); 
        element.value = 
            document.updateForm.lastName.value; 
        element = 
            subMgr.submissionElementForName("phoneNumber"); 
        element.value = 
            document.updateForm.lastName.value;
    
        return; 
    }
  5. Create a new form submission.

  6. Set the form element name/value pair into the submission.

  7. Set the submission attributes, hiding the form so the user cannot edit it from the Forms Manager (they can simply edit the form again), then trash the response.

  8. Set the title of the submission as the ID of the database record so that you can uniquely identify the submission, preventing multiple submissions for an individual record.

  9. Return to the previous page.

    Code for steps 5 – 9:

    subm = subMgr.createSubmission(0, new Date(), 0, 0, 0, 0, 0, 0, 0);
    
        subm.appendSubmissionElement( 
        subm.createSubmissionElement("empId", document.updateForm.empId.value));
    
        subm.appendSubmissionElement( 
        subm.createSubmissionElement("lastName", 
            document.updateForm.lastName.value));
    
        subm.appendSubmissionElement( 
        subm.createSubmissionElement("firstName", 
            document.updateForm.firstName.value));
    
        subm.appendSubmissionElement( 
        subm.createSubmissionElement("phoneNumber", 
            document.updateForm.phoneNumber.value));
    
        subm.status = "UNSUBMITTED_SUBMIT_STATUS"; 
        subm.isHidden = true; 
        subm.trashResponse = true; 
        subm.formIndex = 0; 
        subm.actionMethod = "P"; 
        subm.title = document.updateForm.empId.value; 
        subm.sourceURL = "/EmpDir/update_employee.html"; 
        subm.actionURL = "/EmpDir/update_emp.aspx"; 
        subMgr.saveSubmission(subm);
    
        back();

For more information on using the M-Business XML API, see M-Business XML API Reference.