(1) If you want to use the scope or form id within a form, you could define it like this:
[Form 0 local variables defined in onload function]
var scope = ca_fd.fdScope;
var formId = ca_fd.formId;
(2) If instead you want the variables to be globalc so you can switch between forms, you could do it like this:
[Form 1 global variables defined in onload function]
scopeForm1 = ca_fd.fdScope;
formIdForm1 = ca_fd.formId;
[Form 2 globalvariables defined in onload function]
scopeForm2 = ca_fd.fdScope;
formIdForm2 = ca_fd.formId;
Note: The global variable names can be any non-reserved name you want and could also be stored in an object or array for indexing/iteration purposes. (I create a data structure object called SOE that is accessible from every form. You can use the browser's console to view the variables. If you are going to code with globals get used to using the console for debugging.)
(3) Now that you have the global variables defined you can use the switch scope function. Just substitute the global variables names for the arguments.
syntax:
ca_fd.switchFdScope(scope, formId);
example:
ca_fd.switchFdScope(scopeForm2, formIdForm2);
Warning, you will need to use this function in many places to ensure output is going to the correct form or you are reading values from the correct form. Also, you will need to switch scope in the body of a asynchronous function that is called.
ca_reportQuery('getPolicyApprovers2', {'NAME':formId}, function updateFields(result)
{
if (result.length == 0) return;
ca_fd.switchFdScope(scope,formId);
approver_ids = result[0].approver_ids;
ca_fdSetTextFieldValue(ca_fd.formId, 'policy_approver1', approver_ids);
}, null);