2
votes

I have a custom control with a field where the user will enter a document ID (not a note ID or UNID, just a unique number). This data source is named document1. When they exit the field, I perform a lookup and display either the document with that ID or a new document in an extlib Dialog control (data source bundleDoc). When bundleDoc is saved, I want to update a log field on document1 to indicate that a bundle document was added.

I can save bundleDoc and close (hide) the dialog but the code in my Save & Close button in the dialog can't "see" document1. I can't refer to it using document1.getItemValueString or by getComponent. The getItemValueString returns and empty string and getComponent throws an error because the return value is null.

I would have posted an image to help visually but I don't have enough reputation yet. :( What am I missing? Shouldn't I be able to get to document1 from the dialog control since it is on the same XPage?

UPDATE: Two fields on the dialog form have computed default values that use getComponent to get their values from document1. So, at least when the dialog is loaded, it can see document1. Also, bundleDoc is not defined as a data source for the dialog control. I will try that tomorrow to see if it makes a difference.

UPDATE 2: Still not enough reputation to post a picture, but here is some code. This is one custom control that contains a dialog control. document1 is defined as the data source for the custom control and bundleDoc is defined as the data source for the panel in the dialog control that contains the table of fields for the bundle document.

The BundleID field in the dialog control has a computed default value using this:

if (bundleDoc.isNewNote()) {
    getComponent("inputBundleID").getValue();
} else {
    bundleDoc.getItemValueString("BundleID");
}

The formula for StorageLocationID is similar except that the component is inputStorageTrayID.

This is the code in the Save & Close button:

bundleDoc.save();
var newArr = new Array(document1.getItemValue("WorkLog"));
newArr.push("Added bundle " + document1.getItemValueString("BundleID") + " - " + session.getCommonUserName());
document1.setValue("WorkLog",newArr);
document1.save();
getComponent("dialog1").hide();

The error happens on the document1.save line but it does not get the BundleID from document1 (I set a sessionScope variable to the value of newArr and it showed 'Added bundle - Anonymous'.

2
Don, can you add some of your code tp your question to make it more clear what you are trying to do? This will help you get an answerPer Henrik Lausten
Thanks, Per. Added some code this morning. Hopefully this will push my reputation high enough to post a picture of the control if needed.Don McNally

2 Answers

1
votes

It depends on where you have added the datasources. If document1 is set as the datasource of custom control 1 and bundleDoc is the datasource of custom control 2 you can't access them outside of the custom control they're defined in.

If you add document1 as the datasource of your custom control and create the xe:dialog control (containing a panel with the bunleDoc datasource) in the same custom control you should be able to access document1 (and update/ save it) from a button on the dialog.

0
votes

I think the problem was initially caused by caching issues because it started working the day after I posted the question.

However, I had to do one more thing to get the page to work the way I wanted to. This is the XPage in Designer:

enter image description here

To write a value from the Save & Close button back to the WorkLog field, I had to save the document1 data source before opening the dialog. Then document1 was recognized throughout the Save & Close code and it was saved properly at all times.