Expand my Community achievements bar.

Update control in master template

Avatar

Level 1

Hi;

I am updating a form template that is linked to a master template and would like to use a script to update a text field that is part of the master template. I have written following code to find child nodes of a given node.

     Form.bdyMain.frmMasterOverwrite::validate - (JavaScript, client)

   

    var myNode = xfa.resolveNode("Form");

    for (var i = 0; i < myNode.nodes.length; i++)

    {

        xfa.host.messageBox(myNode.nodes.item(i).name);

    }

For “Form” it returns all the child nodes correctly, but when I replace “Form” with “Form.Portrait_OutboundLetter” no child nodes are found.

Can someone please point me in the right direction how I can access controls that are part of the master template?

FormHierarchy1.pngFormHierarchy2.png

Thanks

Thomas

11 Replies

Avatar

Level 10

Hi Thomas,

Try using "Form.Portrait_OutboundLetter.#pageSet", the pageSet object doesn't seem to be returned by the nodes property.

Also, it is unusual to have nested Master Pages as you do, I would imagine you wont be able to reference mstDummy as it will be hidden by mst ... but then I guess that is why you gave it that name.

Regards

Bruce

Avatar

Level 1

Thanks Bruce, using "Form.Portrait_OutboundLetter.#pageSet" just returns a null reference.

I should have mentioned the templates are provided by a SAP S/4HANA system, this means we can't influence the actual structure too much.

One possible workaround could be to place the field (from the master template) into the form template. This would mean we need to ensure it always printed in the same spot and we are using a flowed layout and I am not sure how we can achieve this?

Regards

Thomas

Avatar

Level 10

Sorry cut-and-paste error on my part, I meant Form.#pageSet.mst.

If you run this you should see the structure in the form DOM (I know would be better being recursive, but just to get the idea..)

var pageSets = xfa.resolveNodes('Form.#pageSet[*]');

for (var i = 0; i &lt; pageSets.length; i++) {

console.println(pageSets.item(i).somExpression);

for (var j = 0; j &lt; pageSets.item(i).nodes.length; j++) {

  console.println(pageSets.item(i).nodes.item(j).somExpression);

  for (var k = 0; k &lt; pageSets.item(i).nodes.item(j).nodes.length; k++) {

   console.println(pageSets.item(i).nodes.item(j).nodes.item(k).somExpression);

  }  

}

}

I don't think you would have much luck with absolute positioning of fields over a multi-page flowed layout

Avatar

Level 1

Hi Bruce;

Thanks again, but not getting anywhere unfortunately.

Running following code

var formNode = xfa.resolveNode('Form');

if (formNode!=null) {

for (var j=0; j<formNode.nodes.length; j++) {

console.println(formNode.nodes.item(j).somExpression);

for (var k=0; k<formNode.nodes.item(j).nodes.length;k++) {

console.println(formNode.nodes.item(j).nodes.item(k).somExpression);

}

}

}

produces the output at the bottom of this response and it can't find any nodes below Portrait_OutboundLetter[0]. I then tried to replace 'Form' with different paths like

Form.Portrait_OutboundLetter.#pageSet[0].mst1

Form.Portrait_OutboundLetter.#pageSet.mst1

Form.Portrait_OutboundLetter.#pageSet[0]

Form.Portrait_OutboundLetter.#pageSet

Form[0]._Portrait_OutboundLetter[0]

Form.Portrait_OutboundLetter

Form.#pageSet.mst

Form.#pageSet.mst1

Form.#pageSet[0].mst

Form.#pageSet[0].mst1

Form.#pageSet[0]

Form.#pageSet

but all of them return null. It looks like none of the controls of the master form are available when I call the script. The script is called in the validate event of a subform, which is part of my form template. Is there maybe another event that I should use?

Regards

Thomas

--- OUTPUT ----

xfa[0].form[0].Form[0]._Portrait_OutboundLetter[0]

xfa[0].form[0].Form[0].Portrait_OutboundLetter[0]

xfa[0].form[0].Form[0]._bdyMain[0]

xfa[0].form[0].Form[0].bdyMain[0]

xfa[0].form[0].Form[0].bdyMain[0]._frmTitle[0]

xfa[0].form[0].Form[0].bdyMain[0].frmTitle[0]

xfa[0].form[0].Form[0].bdyMain[0]._frmAddressAndRightUpperInfoBlock[0]

xfa[0].form[0].Form[0].bdyMain[0].frmAddressAndRightUpperInfoBlock[0]

xfa[0].form[0].Form[0].bdyMain[0]._frmFreeTextBlock[0]

xfa[0].form[0].Form[0].bdyMain[0].frmFreeTextBlock[0]

xfa[0].form[0].Form[0].bdyMain[0]._frmHeaderNote[0]

xfa[0].form[0].Form[0].bdyMain[0]._frmHeadingInvoice[0]

xfa[0].form[0].Form[0].bdyMain[0].frmHeadingInvoice[0]

xfa[0].form[0].Form[0].bdyMain[0]._frmCalculation[0]

xfa[0].form[0].Form[0].bdyMain[0].frmCalculation[0]

xfa[0].form[0].Form[0].bdyMain[0]._frmTableBlock_TE[0]

xfa[0].form[0].Form[0].bdyMain[0].frmTableBlock_TE[0]

xfa[0].form[0].Form[0].bdyMain[0]._frmTableBlock_GroupItems[0]

xfa[0].form[0].Form[0].bdyMain[0].frmTableBlock_GroupItems[0]

xfa[0].form[0].Form[0].bdyMain[0]._frmSummary[0]

xfa[0].form[0].Form[0].bdyMain[0].frmSummary[0]

xfa[0].form[0].Form[0].bdyMain[0]._frmMasterOverwrite[0]

xfa[0].form[0].Form[0].bdyMain[0].frmMasterOverwrite[0]

xfa[0].form[0].Form[0].bdyMain[0]._frmTableBlock_JournalEntries[0]

xfa[0].form[0].Form[0].bdyMain[0].frmTableBlock_JournalEntries[0]

xfa[0].form[0].Form[0].bdyMain[0].event__layout_ready[0]

xfa[0].form[0].Form[0]._frmHiddenGlobalFields[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtFormTitle[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtDocumentID[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtBillingSDDocumentCategory[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtBillingSDDocumentCategoryName[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtIsPreview[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtDocumentTitle[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtCancelledCustomerInvoiceID[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtContainsDataTimeExpense[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtContainsDataProjectService[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtContainsDataProjectExpense[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtTransactionCurrency[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].decSEPAAmount[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtSEPAIBAN[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].txtSEPABank[0]

xfa[0].form[0].Form[0].frmHiddenGlobalFields[0].dtSEPAPaymentDueDate[0]

xfa[0].form[0].Form[0]._frmHiddenStaticTexts[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblCancellationInvoice[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblInvoice[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblCancellationInvoiceNumber[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblInvoiceNumber[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblPreview[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblFixPrice[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblService[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblServicesFor[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblExpensesFor[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblSubtotal[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblFrom[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblTo[0]

xfa[0].form[0].Form[0].frmHiddenStaticTexts[0].lblSEPASentence[0]

Avatar

Level 10

Hi,

I would have expected "Form.#pageSet.mst1" to have worked (sorry got it wrong a second time), I thought all the master pages were put under Form.#pageset regardless of where they were defined, so I would not expect to find anything under Portrait_OutboundLetter

Is it possible for you to share your form.  If you could load it on any file sharing site and post a link here, even one without the bdyMain included ... unless there's another (Master Pages) element nested in there that is hiding the one we can see in your structure

Bruce

Avatar

Level 1

Hi Bruce;

Thanks again for your reply. below is a link to the form.

https://borncreations.sharefile.com/d-s128e315c7e040eca

Regards

Thomas

Avatar

Level 10

Hi,

The fragment "Portrait_OutboundLetter" was missing from your upload, so I am still unsure of your form structure or even why you have the nested master pages.

To reference mst1 or mst2 then I thought you needed something under "Portrait_OutboundLetter" to reference them, which has the effect of adding them to the form DOM and therefore showing up in my code above.

So by default the first master page will be used.  To reference the second master page (that is mst2) then there should be a subform with a pagination setting place in page "mst2" under Portrait_OutboundLetter.

I've modified your form by moving the form pages under Portrait_OutboundLetter (so they reference mst2), adding a new subform that references mst2 and a button with my code from above in it.

https://sites.google.com/site/livecycledesignercookbooks/home/YY1_MCN_INVOICE_BASIC_E%20-%20JavaScri...

Hopefully this helps, but if not share the fragment as well.

Regards

Bruce

Avatar

Level 1

Hi Bruce;

I really appreciate your help. Unfortunately this won't help much I believe it is the way SAP does the Master / form template merge in their system.

Currently our system is unavailable but will try to place the javascript code into the master template instead and see if this works. Not ideal but the master is specific to the invoicing document so it shouldn't really matter.

As a last resource I could add additional nodes into the data source and then use binding. Will update once I have access again.

Thanks again

Thomas

Avatar

Level 10

Hi Thomas,

I've never used SAP, but it does seem wrong unless you have a normal page under Portrait_OutboundLetter at the same level as (Master Pages) you wont be able to reference mst1 or mst2 so they will never exist in the Form DOM

Bruce

Avatar

Level 1

Hi Bruce;

Unfortunately I am not that familiar with Adobe LiveCycle Designer. I have tried setting the value from within the master template and this works. Not pretty but it does the job in this instance.

Thanks again for the time you spent on this. Really appreciated.

Regards

Thomas

Avatar

Level 1

Hi Thomas,

Just drop the fragment name from the path. Once the master template is merged with the normal template, SAP drops this object from the result.

So in your case use Form.#pageSet...... instead of Form.Portrait_OutboundLetter.#pageSet......

Regards,

Alfredo Sanchez