Is there a way I can get the field value of a document if I know the document UNID?
I have the following code:
var a = database.getDocumentByUNID(sessionScope.unid);
sessionScope.unid contains the documentUNID.
I can't see any methods avaible if I do a. . Is there something wrong?
SSJS does not provide typeahead unless you specifically cast variables as the class you wish to use. So to get typeahead you need to use:
var a:NotesDocument = database.getDocumentByUNID(sessionScope.unid);
Related
I have a hidden field in crm form and setting value for hidden field on save button click using JavaScript.
I am trying to select the hidden filed value in c# plugin code on postcaseCreate event, but getting Key is not found in dictionary error, Can anyone tell me what I am missing here.
if (localContext.PluginExecutionContext.InputParameters.Contains("Target")
&& localContext.PluginExecutionContext.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parmameters.
caseEntityObj = (Entity)localContext.PluginExecutionContext.InputParameters["Target"];
string productIds = caseEntityObj.FormattedValues["my_hiddenfiedld"].ToString();
if (caseEntityObj == null) return;
}
Try to replace line
string productIds = caseEntityObj.FormattedValues["my_hiddenfiedld"].ToString();
with line
string productIds = caseEntityObj["my_hiddenfiedld"].ToString();
Why do you want to use FormattedValues? Is hidden field optionset? If yes and you need to get correspond text you will have to retrieve attribute using RetrieveAttribute message and get text of optionset from response.
The "Target" input parameter has only the attributes that were submitted to the framework. The system forms only submit attributes that contain changed data (or do not equal default values) as an optimization. If you created your own client UpdateRequest or CreateRequest and only submitted a few attributes, then your plugin's Target collection would only contain those few attributes as well.
In your case, I'm guessing that your hidden field isn't changing on an update and so it isn't included in your Target attribute collection.
If your plugin logic will always need to know the current value of a field regardless of whether it is included in the submitted attribute collection, you need to register a PreImage. Registering a PreImage tells CRM that you always need to know the current value of a certain field during this plugin. This is the value of the field before the current action.
Docs on PreImages: https://msdn.microsoft.com/en-us/library/gg309673.aspx#bkmk_preandpost
Pseudo code:
Use .Contains() to check Target attribute collection for attribute name.
If true, get value of attribute from Target attributes as this is the actual change just submitted by client.
If false, use .Contains() to check PreImage attribute collection for attribute name.
If true, get value of attribute from PreImage as this is the most recent value from the database.
Hope that helps!
Thanks Josh,Andril,
I created two steps in plugin code like postCaseCreate,PostCaseupdate event and one postImage and then I am getting value like below on postCase create event
string productIds = caseEntityObj["my_hiddenfiedld"].ToString();
For update getting the value from image. It is working fine. thanks a lot guys.
Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;
productIds = postImageEntity.Attributes["my_hiddenproducts"].ToString();
There is a viewPanel1 that lists some docs. and having also the var property set to rowData.
How can I easily get the datasource name for a clickable doc / row ? Is there a 'quick' method something like:
rowData.getDocument()./* getting the datasource name */ ?
Thanks for your time.
You can not get the data source name for the document but rather the form name. Based on the form name you can then decide on an action for that particular document.
Use the following:
rowData.getDocument().getItemValueString("Form")
I have a content item called Event, which has a taxonomy field called Section attached via the content definition area.
What is the easiest way to retrieve the Section field from the content within an alternate? My alternate is not overriding an Event, so Model.ContentItem is not possible. Within my alternate my Event object instance is of type ContentItem which I am retrieving through the ContentManager.
This is what i'm doing at the moment:
ContentItem content = WorkContext.Resolve<IContentManager>().Get(id);
var = content.Parts.ElementAt(13).Fields.ElementAt(0);
I realise that in the above code the index's could change, the only other way I can think of doing this is by inserting Lambda expressions in the place of the integers.
content.Parts.ElementAt(13) returns object of type ContentPart
content.Parts.ElementAt(13).Fields.ElementAt(0) returns object of type TaxonomyField. Whereas I believe I need the TermPart?
If it cannot be achieved in a simple way, why is it so difficult to perform such a simple task?
Thank you in advance.
First you do not need the ContentManager on the template.
On the Model you have the ContentItem. You can retrive the field like this:
var contentItem = Model.ContentItem;
var terms = contentItem.Event.TaxonomyFieldName.Terms;
On terms you have the terms of the ContentItem.
Before describing the problem, I would like to add that I have looked for this problem on google and have found many solutions but none related to XPAGES. Since, Xpage have a unique method to generate the field id I am facing this problem. I have also posted the same question here on IBM forum and awaiting the reply there(http://www-10.lotus.com/ldd/ndseforum.nsf/xpTopicThread.xsp?documentId=EDEBB14BDF2E804F85257BE8001E4F76):
Problem:
I am trying to pass dynamic id to the default function getElementById with no success. To explain it clearly, I have a front end validation for specific fields. This fields are stored n database. So, I have a for loop running for all the fields. The problem here is that XPages generates the Id dynamically and hence for the same form if there is a hierarchical tabbed panel then the Id also included the tabbed panel Id in it.
Here is the code view of the problem:
The standard method to retrieve the value(CSJS) is:
document.getElementById("#{id:inputText1}").value;
However, if I try to pass in a dynamic id. It doesn't work. I have tried "n" number of approaches I found on Google but none regarding this problem. One solution I tried here was:
var x = "inputText1";
document.getElementById("#{id:"+x+"}").value;
Any help would really be appreciated. Really eager to hear some good suggestion.
The "#{id:inputText1}" part is computed at the server before the page is served so it's too late to set the ID in client side JS.
To set the ID in SSJS you can do this:
document.getElementById("#{javascript:var x='inputText1'; getClientId(x)}").value;
With getClientId you can also build a CSJS array of IDs in in SSJS. Then you can loop that array in CSJS. You would build the array this way:
var strIDs = ${javascript:'["a","b","c"]'};
I have a custom entity in CRM 2011 with a Closure Code(drop down list) and Solution(multiple lines text) fields.
Is weird what is happening, and this is that the next sentence, is not getting the actual field value:
var detailsSet = Xrm.Page.getAttribute("aux_solution").getValue();
Why this could happen?
As explained in the comments, my problem was that the field wasn't taking the actual value because the focus was on it. Moving to another field before checking the values is how I solve this. I hope could help someone.
That is because the object model does not get refreshed data while you have focus on the field. If you want to get the value without having to click outside you need to use the good old document.getElementById .
If it is an option set, you should use eiter getSelectedOption() or getText()
so try
var detailsSet = Xrm.Page.getAttribute("aux_solution").getText();
For more details refer this