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();
Related
I am using the podio-js package in a project designed to handle our invoicing. I am currently facing a problem in my attempts to update an item's category type field.
Here is the code I am currently running with:
const url = `/item/${item_id}/value/${field_id}`;
// newOptionId is the id of the option I want to switch to
const requestData = JSON.stringify({[field_id]: newOptionId});
const responseData = await this.podio.request('PUT', url, requestData);
I tried several other formats as described here: https://developers.podio.com/doc/items/add-new-item-22362, but every time I get the same result, it unselects the current selected option and leaves my category type field with no selected option.
Please provide me with the correct requestData format as I think the problem is coming from there.
Thanks.
The request format {value: your_id} is not supported anymore, it worked for me using this.podio.request('PUT', url, [myId]) to update a category field.
#Podio team: it would be cool to update and complete your documentation.
There are 4 slightly different ways of setting value to a field.
1. One when creating new item Podio: create item
2. Another one when updating whole item Podio: update item. This includes for example reverting to specific revision or setting each and every field including meta-fields like files, reminders, recurrences, etc.
3. Yet another one is updating item value Podio: update item value, which is updating whole item but only fields. So, it only accepts content that is inside fields parameter for methods #1 and #2 above.
4. And one more is for updating item field values Podio: update item field values. This one expects values for single field and only content of fields['field_id'] from methods #1 and #2 should be passed here.
Each way requires different format for value and uses different url.
I've updated documentation to include 2 cURLs examples for last 2 methods to make it clear, but will be happy to include additional explanations if you provide them.
Quick question.
I have a custom two-option field on an entity, with "Yes"/"No" as the values; "Yes" has the underlying value 1, while "No" has the underlying value 0. I've set the default value for this field to "Yes". However, when I create new entity records, the field always gets the value "No" (0 in the database). It seems to be ignoring the default value I've set. Why?
The field is not present on any of the entity forms, as it's only used in underlying plugin code. Should that matter?
Are you creating a new record for this entity using code that uses the strongly-typed objects? If so, when you create a "new" entity in code, I'm guessing the class itself is setting that field to "false" by default. I don't think those generated classes respect the default values in the metadata. I also think that all fields are submitted on a create when you use these generated classes. That means that your class is setting it to "no" by default and then on create, the system thinks that you explicitly set it to "no" so default values are not applied. I think you need to explicitly remove that attribute from the attribute collection of your entity before you create it. That way the system should respect the default value on create. Sorry for all the "I thinks" but I'm not in a place that I can test or verify all of this. :)
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);
EDIT: Rephrased issue
I think there is either a bug or I am doing something wrong.
I add a field to the type Blogpost. This field is of type
Contentpicker. I call it Related Page.
Then I create to regular pages (ContentType Page).
I create 4 blogposts. Two blogposts get PageOne as selected value in the RelatedPage field. The other two posts get PageTwo as selected value in the RelatedPage.
Now I create a query with filter ContentType is BlogPost. And a filter with Blog Post.Related Page equals {21} (that is the Id of PageOne).
I would expect to get results BlogPostOne and BlogPostTwo. Instead I don't get results. Actually I wanted the pageid to be retrieved from the page the widget is placed on but couldn't get it to work, so I reduced back to a predefined value instead of dynamic for the filter. But like I said no results.
So is the query wrong and how should I do it then. Or is there a bug with filters for ContentPicker fields.
P.S. I will also submit an issue in Codeplex.
UPDATE
In Tokenizer all the values that contain { } are being seen as tokens and therefore are replaced. The problem is that the Ids of content items in a contentpicker field are stored with accolades. So when having {21} as the value for the filter, 21 gets tokenized and since there is no value for this token the value becomes empty. When skipping the tokenizer it works (while debugging). But one cannot skip the tokenizer, because it is very legitimate that there is a token present.
So I believe there is a bug with either the tokenizer, or the way the ids are stored in the contentitem field for contentpicker. I think it can be solved by changing the contentpicker to store numbers separated with comma's but without the accolades.
have you tried using the alias of the page instead of content id as the identifier? e.g. "/about-us", like you do in the layer rules.
I'm using Sharepoint 2010's web services interface to try to get the columns for a given list. I've got not problem with getting all of the columns using a GetList() call, but the issue is that I need to only get the columns that the user can see in the List Settings view of the Sharepoint UI.
The code that I'm currently using is as follows:
rootNode = serviceReference.GetList(List_id.ToString());
Element element = XElement.Parse(rootNode.OuterXml);
var fields = from e in element.Descendants()
where e.Name.LocalName == "Field" && e.Attribute("ID") != null &&
!(e.Attribute("Name").Value.StartsWith("_") && e.Attribute("SourceID").Value == "http://schemas.microsoft.com/sharepoint/v3")
select e;
Where serviceReference is an instance of the Sharepoint Lists Service and List_id is the GUID representing the list internally to Sharepoint.
This does filter out some of the columns that I don't want, but it doesn't get rid of everything.
Does anybody know what attributes I'm looking for to narrow it down just to the ones that the user can select to be added to a view? Or am I going about this entirely the wrong way?
Many thanks for any help.
The answer to this was that I was indeed looking in the wrong place for the information I needed. As user823959 pointed out, I needed to get the content type definition and use the fields in there rather than the list itself.
To do this was a two stage process, firstly we need to get the list of content types using the Lists.GetListContentTypes method (although this takes a content type id parameter, it doesn't actually seem to matter what we put here)
XmlNode rootNode = serviceReference.GetListContentTypes(List_id.ToString(), "0×01");
The CAML returned contains the definitions for each of the content types that are available in the list - with the first content type returned being the default one (in my case, the one I was after)
String contentType = rootNode.ChildNodes[0].Attributes["ID"].Value;
Once we've got the content type that we're after we can make a call to GetListContentType with the appropriate list content type id to get the full definition of the content type:
XmlNode contentTypeNode = serviceReference.GetListContentType(List_id.ToString(), contentType);
The CAML returned from this call will contain a list of field elements that correctly show the fields that are available in the SharePoint UI's view configuration. They can be selected in a LINQ query like this:
XElement contentTypesElement = XElement.Parse(contentTypeNode.OuterXml);
var fields = from e in contentTypesElement.Descendants()
where e.Name.LocalName == "Field"
select e;
At this point, we've got a list of Field XML elements that contain information about display names, static names, content types and a whole lot more. See Microsoft's documentation on the Lists.GetListContentType page for more information on the range of information returned about each field.
Many Thanks to user823959 for pointing me in the right direction.