Page 1 of 1

back button issue within sub-process

Posted: Thu Feb 15, 2018 4:00 pm
by Throwaway
I have it set up using a back button with the attached code. The js works fine on the main process, but once we go into a sub-process and use a back-button, it just brings up a "submit" button and it freezes once you click it. So you have to restart the case.
Code: Select all
$(document).delegate("#btn_back", "click", function (e) {
	if (typeof localStorage["flagBackButton"] === "undefined" || localStorage["flagBackButton"] === "FALSE") {
		showSpinner();
		localStorage["flagBackButton"] = 'OK';
		appUid = app_uid;
		access_token = localStorage['pmAccessToken'];
		server = localStorage["restServer"];
		workspace = localStorage["workSpace"];
		$.ajax({
			type: 'POST',
			url: server + '/api/1.0/' + workspace + '/plugin-psLeadRegistrationPlugin/back-button',
			data: { APP_UID: appUid },
			beforeSend: function (xhr) {
				xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				xhr.setRequestHeader("Authorization", "Bearer " + access_token);
			},
			success: function (e) {
				spinner.stop(spinner_div);
				pmRestRequest('GET', '/api/1.0/' + workSpace + '/cases/' + app_uid + '/variables', false, null, getCase);
			},
			error: function (e) {
				console.log(e);
			}
		})
	} else {
		alert('Error: You can only go one task backwards!');
		$("#btn_back").attr("disabled", "disabled");
		localStorage["flagBackButton"] = "BLOCKED";
	}
	e.preventDefault();
});

Re: back button issue within sub-process

Posted: Thu Feb 15, 2018 10:08 pm
by amosbatto
When you are in a subprocess case, the Case UID and delegation index are different from the master case. Where are you getting your app_uid variable from?

Re: back button issue within sub-process

Posted: Fri Feb 16, 2018 9:28 am
by Throwaway
amosbatto wrote:When you are in a subprocess case, the Case UID and delegation index are different from the master case. Where are you getting your app_uid variable from?
Code: Select all
// reset current page to 1 for grids & pagination
	showSpinner();
	currPage = 1;
	if (form.app_uid) {
		app_uid = form.app_uid;
	}
This is where the app_uid is being grabbed from, so I guess it might be trying to use the first process id instead of the subprocess.

Re: back button issue within sub-process

Posted: Fri Feb 16, 2018 8:21 pm
by amosbatto
If you are getting the app_uid from the Dynaform properties, then it should be the correct case ID for the subprocess case, but check it to make sure.

Are you sure that your POST parameters are working?
If your custom REST endpoint can't read the APP_UID, then try this:
Code: Select all
         data: JSON.stringify({ APP_UID: appUid }),
         beforeSend: function (xhr) {
            xhr.setRequestHeader("Authorization", "Bearer " + access_token);
         }, 

Re: back button issue within sub-process

Posted: Mon Feb 19, 2018 9:39 am
by Throwaway
amosbatto wrote:If you are getting the app_uid from the Dynaform properties, then it should be the correct case ID for the subprocess case, but check it to make sure.

Are you sure that your POST parameters are working?
If your custom REST endpoint can't read the APP_UID, then try this:
Code: Select all
         data: JSON.stringify({ APP_UID: appUid }),
         beforeSend: function (xhr) {
            xhr.setRequestHeader("Authorization", "Bearer " + access_token);
         },

Should this go in the same location as where we are currently grabbing the app_uid or would it go somewhere in the process?

Re: back button issue within sub-process

Posted: Mon Feb 19, 2018 11:40 am
by amosbatto
This is replacing the jQuery code that you posted, which I assume you are used in a DynaForm in the subprocess case.

You have to look at the code in plugin-psLeadRegistrationPlugin/back-button.php to determine if it expects a JSON string or not. If it expects JSON, then try using this jQuery code:
Code: Select all
     $.ajax({
         type: 'POST',
         url: server + '/api/1.0/' + workspace + '/plugin-psLeadRegistrationPlugin/back-button',
         data: JSON.stringify({ APP_UID: appUid }),
         beforeSend: function (xhr) {
            //xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //probably not necessary if using JSON
            xhr.setRequestHeader("Authorization", "Bearer " + access_token);
         },
         success: function (e) {
            spinner.stop(spinner_div);
            pmRestRequest('GET', '/api/1.0/' + workSpace + '/cases/' + app_uid + '/variables', false, null, getCase);
         },
         error: function (e) {
            console.log(e);
         }
      })

Re: back button issue within sub-process

Posted: Mon Feb 19, 2018 11:44 am
by amosbatto
By the way, is plugin-psLeadRegistrationPlugin your custom plugin? If not, where did you get it?

Re: back button issue within sub-process

Posted: Wed Jun 10, 2020 12:50 pm
by oaghwotu
Hello there. My app_uid returns null or empty. I have tried these two methods to return the app_uid, to no avail.
Code: Select all
const app_uid = PMDynaform.getProjectKeys().caseUID; 
const app_uid = frames.app_uid ? frames.app_uid : ''; 
Really appreciate your help.