Dynamics CRM is ignoring the default value for two-option field - dynamics-crm-2011

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. :)

Related

How to use <sw-entity-multi-select> correctly?

I am a bit confused how to use the component <sw-entity-multi-select>. I understand that the difference between this component and the <sw-entity-multi-id-select> is that the first one returns the entities and the latter one returns just the id of the selected entities. But from the structure and the props they are totally different.
I am confused, because I mainly use the component as this:
<sw-entity-multi-select
entityName="language"
:entity-collection="languages"
:criteria="salesChannelLanguageCriteria"
:label="Language"
#change="selectLanguage"
>
</sw-entity-multi-select>
I could remove the entityName here, as the name is retrieved from the collection as well. But when I dig into the core, I see that inside selectLanguage I should do this:
selectLanguage(languages) {
this.languageIds = languages.getIds();
this.languages = languages;
}
I now understand that languageIds are kind of the v-model that determine, which entities should be selected in the component. Is this true? Why do I have to set the this.languages here again then? To me it's kind of magic if languageIds have this role here, because it's not referenced anywhere on the component. How does it work and how do I tell the component which items are selected - is using languageIds the correct way?
I now understand that languageIds are kind of the v-model that determine, which entities should be selected in the component. Is this true?
No. This example probably just extracts the IDs for some other use, e.g. for adding associations of language to another entity. One could arguably that if this is the only purpose of the selection sw-entity-multi-id-select might be the better component to use.
Why do I have to set the this.languages here again then?
Because you want to store the updated entity collection to persist the selection. Whatever is selected within the multi select is derived from that collection. So, let's say, initially you start out with an empty entity collection. You select some entities and the change is emitted with the updated collection containing the selected entities. Given we have :entity-collection="languages" we then want this.languages to be this updated collection, so the selection persists. So we kinda complete a loop here.
On another note, you could also use the collection with v-model="languages". In that case any additions or removals within the selection would be applied reactively to the collection and you wouldn't need to set this.languages after each change and you could also remove :entity-collection="languages". So basically, which of these approaches you use depends on whether you want your changes applied reactively or not.

Maximo readonly/persistent attribute issues

I have an non-persistent attribute (SITEID) on my WOCHANGE object that originates from the parent object, WORKORDER. For some particular reason, this attribute has a few problems that I've never really seen with other attributes before.
Based on various configurations I have tried in an attempt to remedy the issue, here are the main issues:
It doesn't trigger the WOCHANGE to save when changed.
In addition to the value not being saved, I can change the value on one record, go to another and the value persists on the different record.
The field is readonly unless I define it to have an inputmode of DEFAULT. This is odd to me, because not defining inputmode usually implies default behavior (NOT readonly).
Here are the definitions for the SITEID attribute on both the WORKORDER
and WOCHANGE objects.
SITEID also uses a TABLE domain belonging to the SITE table.
Are there any attribute rules being applied from other sources that I should be checking?
That workorder field class on there may not be desired and may be messing with things, like setting the field to read-only. Site Id is commonly a read-only field, especially when the record is no longer a new record. Because of that, the logic to make that field read-only could be buried deeper in the Maximo business logic than just that field class. You are working with a field that has a lot of special meaning in Maximo, you are likely going to stumble into many built-in business rules.
Since non-persistent fields are not saved in the database (they are in memory fields only), I don't believe they trigger the flag for a record to be saved. What would be saved? Nothing in the database (a save) is to be changed yet.
Your screenshot however shows the field as persistent. Is WOCHANGE a view? I can't recall and no longer have the resources to check.

Formula referencing parent doc works in computed field, not as default value

Following on from this question: Referencing parent field on document creation I'm using the formula for the default value for a name field.
IfError(#IfError(#GetDocField($ref;"ProductFamilyManager");
#GetDocField(ParentUNID;"ProductFamilyManager"));
"")
This works when it's a computed field, but not when i change it to be editable with a default value formula.
Any ideas how I can get the field populating with the default value?
The best way of doing this is to use #InheritedDocumentUniqueId. You need to enable inheritance to make that function available, but you don't actually have to inherit any of the parent values.
You should definitely not have to be using two different techniques and #IfError to get this done. And btw: did you know that #IfError is obsolete as of Domino 7?
It may not be supported but just to be sure, has the parent doc been saved before you create the response doc?
Assuming that's not the problem, the alternative is to use the "inherit field values from parent doc " option, which will pass a value from the parent doc to the response doc on creation. I may have the wording wrong but the option is on the form properties dialog in Designer.

Siebel read only field problem

I'm trying to make a field read only when a given value is selected from a PickList.
I'm using a flag that is set to Y when the list has that value, and N otherwise.
I created a Business Component User Prop with the name Field Read Only Field: MyField set to the flag.
Thing is, this works with the vanilla component but it wont work on my custom component.
I can't figure out what is going on, the properties of the fields and flag are exactly the same. It should work...
Thanks for any help you can give me.
That user property is only supported on the business component class CSSBCBase and its subclasses. My guess is that you probably used CSSBusComp as the class of your business component. CSSBusComp is actually a superclass of CSSBCBase, and is very minimal and does not support Field Read Only Field. If that's the case, change it to CSSBCBase and you should be good to go.
Other option is that- if the record become read-only when the picklist value is being selected- that you'll need to make the picklist field Immediate Post Changes to be sure the user property is triggered.

Removing ';#' from SharePoint ListItem data

In SharePoint many fields id-value pairs that are formatting like the following id;#value. This is further complicated with fields like multi-lookup where when extracting the value of that field can yield results like id_1;#value_1;#id_2;#value_2;#id_3;#value_3
I am wondering if there is any known built in function that will simplify this process and at the very least remove the IDs from the value.
Field value objects are stored as strings in the Sharepoint database. For simple values (e.g. "Hello world") this is simple enough. But for complex field values - such as an ID/value pair, how to store the entire value as a single string is obviously more complex as well. Each field value class in Sharepoint is responsible for its own storage implementation. ToString() is responsible for writing a string representation of the value; while the field value's constructor takes a string and is responsible for parsing that and setting all the properties on itself appropriately.
For example, the SPFieldUrlValue (which represents an description) has Url and Description properties. Creating a new SPFieldUrlValue(string fieldValue) object will parse the value and set the properties accordingly.
In order to get a true/correct (and often strongly-typed!) representation of the field value, you must know what type the field is, and what that field's value class is.
The SPField class has many derived classed
For example assuming a Lookup field type (that uses the ID;#value) you can check SPField.Type == SPFieldType.Lookup and then cast SPField to SPFieldLookup and use its overriden methods to get the records value.
See Custom Field Value Classes for more details
Also - If I remember correctly (I can't check this right now so DYOR) you can call .ValueAsText and .ValueAsHtml on the base SPField object and it will remove ID;# from the values.

Resources