How to copy the details from one form to another form in service portal?

RevathiV
Giga Expert

Hi all,

 

I have a record producer Form A on portal and after submitting this form A, a button 'Proceed' will be visible. On click of this button another record producer Form B will open on the portal (The code for onclick of this button is written in a widget).

 

The Requirement is, I need to copy certain values submitted in Form A and populate it onload in Form B. 

 

Could you please suggest on how to achieve this requirement. 

 

Many Thanks

1 ACCEPTED SOLUTION

Revathi10
Tera Expert

Step 1:
The code for onclick of 'Proceed' button is written in a widget - In this widget in Client Controller I added

window.open('portal_url_of_record_producer_B&formARec='+$scope.data.sys_id,'_blank');

here $scope.data.sys_id contains the sys_id of the record on submit of Record Producer A.

Step 2:
I created an OnLoad Catalog Client Script on Record Producer B.
Script: 

function onLoad() {

var urlParams = new URLSearchParams(location.search);
var tempRecordID = urlParams.get('formARec');

if (tempRecordID) {
var ga = new GlideAjax(<Script Include name>);
ga.addParam('sysparm_name', <func name>);
ga.addParam('sys_id', tempRecordID);
ga.getXML(myCallBack);

function myCallBack(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
var recData = JSON.parse(answer);

g_form.setValue('<field_name>', recData.<field_name>); 

// Added setValue for all the fields that need to be populated on Record Producer B
}

}
}

Script Include:

 var tempRec = this.getParameter('sys_id');
        var formRec = new GlideRecord('<record producer A table>');
        if (formRec.get(tempRec)) {
            var obj = {};
                obj = {
                    key: value,
                    key2: value2
                };
            return JSON.stringify(obj);
        }

View solution in original post

3 REPLIES 3

JenniferRah
Mega Sage

You may want to look into order guides. The user can fill out the shared fields on the "Describe Needs" section and then be forced to create both Form A and Form B in the "Fill Out Form" section, and you can populate the fields in both forms.

Ravi Chandra_K
Kilo Patron
Kilo Patron

Yes, As Jennifer mentioned order guide suit for this requirement...

 

Please mark the answer as helpful and correct if helped. 

Kind Regards,

Ravi Chandra  

Revathi10
Tera Expert

Step 1:
The code for onclick of 'Proceed' button is written in a widget - In this widget in Client Controller I added

window.open('portal_url_of_record_producer_B&formARec='+$scope.data.sys_id,'_blank');

here $scope.data.sys_id contains the sys_id of the record on submit of Record Producer A.

Step 2:
I created an OnLoad Catalog Client Script on Record Producer B.
Script: 

function onLoad() {

var urlParams = new URLSearchParams(location.search);
var tempRecordID = urlParams.get('formARec');

if (tempRecordID) {
var ga = new GlideAjax(<Script Include name>);
ga.addParam('sysparm_name', <func name>);
ga.addParam('sys_id', tempRecordID);
ga.getXML(myCallBack);

function myCallBack(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
var recData = JSON.parse(answer);

g_form.setValue('<field_name>', recData.<field_name>); 

// Added setValue for all the fields that need to be populated on Record Producer B
}

}
}

Script Include:

 var tempRec = this.getParameter('sys_id');
        var formRec = new GlideRecord('<record producer A table>');
        if (formRec.get(tempRec)) {
            var obj = {};
                obj = {
                    key: value,
                    key2: value2
                };
            return JSON.stringify(obj);
        }