Not able to see the label of the Api names - pagination

SelectedFields is the list of the fields having API Name and itr the iterative variable and similarly rec is the iterator variable for the records So whenever I am using {!itr}
in the facet then it will print API name and If do not use facet then it will print label of the fields how to fix this??
<apex:repeat value="{!selectedFields}" var="itr">
<apex:column value="{!rec[itr]}">
<apex:facet name="header">
<apex:commandLink action="{!sortByColumn}" reRender="recPage">{!itr}
<apex:param name="Names" value="{!itr}" assignTo="{!sortingValues}"/>
</apex:commandLink>
</apex:facet>
</apex:column>

Can you use $SobjectType to get the field label, something like {!$ObjectType.Account.fields[itr].label}?
Alternatively in apex build a Map<String, String> where key is the api name and value is the label. Or you can even iterate over list of field tokens, not strings. sObject class supports a dynamic get with field token as param so same trick should work in VF and you can get label out of a token too.

Yeah! {!$ObjectType.Account.fields[itr].label} It is the way to get the Label from the API name of Objects and For the dynamic objects. We can use this {!$ObjectType[sObject].fields[itr].label} as it will take out the label from the API names.

Related

Retrieve OptionSet from Dynamics Web API MetaData

I'm trying to retrieve the option set values (localized labels and integer Ids) for a specific field on a specific entity. Below is the code that I am using, but every time I execute it, it brings back ALL optionsets that are currently in my system (about 800+) and I don't want to do that.
EntityDefinitions(LogicalName='#MY_ENTITY#')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$filter=LogicalName eq '#MY_ENTITY_ATTRIBUTE#'&$expand=OptionSet
maybe this can help,
/api/data/v9.1/ENTITY(guid OR Filter)?$select=ATTRIBUTE1,ATTRIBUTE2
include header:
{
"Prefer": "odata.include-annotations=OData.Community.Display.V1.FormattedValue"
}
this gives us a response like this:
{
"ATTRIBUTE1#OData.Community.Display.V1.FormattedValue": "Person",
"ATTRIBUTE1": 1,
"ATTRIBUTE2#OData.Community.Display.V1.FormattedValue": "Company",
"ATTRIBUTE2": 2
}
I'm using the stringmap entity to retrieve the optionsets.
This represents the optionsets as a simple table on which you can filter in the query
For example by calling:
/stringmaps?$filter=(objecttypecode eq 'contacts')
you get only the optionsets which are use in the contact entity. You can also filter on attribute name, the option value (field value) or option id (field attributevalue).

Fill some fields from other module based on many2one field

I have 3 fields
Pick_no= fields.many2one(stock.picking)
Partner_id= field.char
Location_id=field.char
I want to auto fill partner and location fields based on the selected pick_id.
What should I use onchange or depends?
IMO You may use onchange() method.
Need to change field datatype. Go to stock.picking model and verify datatype. In your case, you declared with char. It is not wrong but not advisable. If you want to keep char then assign char value, not ID.
partner_id = fields.Many2one(res.partner)
location_id = fields.Many2one(stock.location)

Binding an edit box within a custom control to a form field programatically

I have a notes form with a series of fields such as city_1, city_2, city_3 etc.
I have an XPage and on that XPage I have a repeat.
The repeat is based on an array with ten values 1 - 10
var repArray = new Array() ;
for (var i=1;i<=10;i++) {
repArray.push(i) ;
}
return(repArray) ;
Within the repeat I have a custom control which is used to surface the fields city_1 through city_10
The repeat has a custom property docdatasource which is passed in
It also has a string custom property called cityFieldName which is computed using the repeat
collection name so that in the first repeat row it is city_1 and in the second it is city_2 etc..
The editable text field on the custom control is bound using the EL formula
compositeData.docdatasource[compositeData.cityFieldName]
This works fine but each time I add new fields I have to remember to create a new custom property and then a reference to it on the parent page.
I would like to be able to simply compute the data binding such as
compositeData.docdatasource['city_' + indexvar]
where indexvar is a variable representing the current row number.
Is this possible ? I have read that you cannot use '+' in Expression Language.
First: you wouldn't need an array for a counter. Just 10 would do (the number) - repeats 10 times too. But you could build an array of arrays:
var repArray = [];
for (var i=1;i<=10;i++) {
repArray.push(["city","street","zip","country","planet"]) ;
}
return repArray;
then you should be able to use
#{datasource.indexvar[0]}
to bind city,
#{datasource.indexvar[1]}
to bind street. etc.
Carries a little the danger of messing with the sequence of the array, if that's a concern you would need to dig deeper in using an Object here.
compute to javascript and use something like
var viewnam = "#{" + (compositeData.searchVar )+ "}"
return viewnam
make sure this is computed on page load in the custom control
I was never able to do the addition within EL but I have been very successful with simply computing the field names outside the custom control and then passing those values into the custom control.
I can send you some working code if you wish from a presentation I gave.

SharePoint: Problem with Custom Field EntityEditorWithPicker

I have a custom field derived from SPTextField displays EntityEditorWithPicker while in New or Edit mode (I have extended my class from EntityEditorWithPicker). I have added that field as column to a list. When I select any item from the Dialog, it adds that item to the list column. Fine till here. Fine upto this point.
But when I go to Edit any item in the list, it shows the EntityEditorWithPicker on the edit item page but textfield is empty. I want that the value in the list should appear in the textfield in the EntityEditorWithPicker. How can I achieve that.
Thanks in davance for the help.
Best regards,
Asher
We have UpdateEntities() method in EntityEditorWithPicker class (Please note that we need to extend this class for use in our code) that accepts the object of ArrayList. Create EntityPicker Object, populate the Key property (Key property will appear in the Textbox as you want), add EntityPicker object in ArrayList Object and then pass ArrayList Object to UpdateEntities() method. We are done!!!
MyExtendedEntityEditorWithPicker _recordPicker = new MyExtendedEntityEditorWithPicker();
ArrayList entities=new ArrayList();
EntityPicker entity=new EntityPicker();
entity.Key="Value To be Displayed in Textbox";
entities.Add(entity);
_recordPicker.UpdateEntities(entities);
I hope this helps!
Azher Iqbal

Can I set the default value of a custom list column to be a new Guid?

I tried setting the defaultvalue property of the field to Guid.NewGuid() but every item created has the same guid so I guess the Guid.NewGuid() is being stored as the default rather than being run each time.
Is the only way to achieve this to add an event handler to the list for OnAdded?
I'm assuming you're using a Single Line of Text field for this. The standard default for such a field is always a constant, you can't assign a variable or function via the object model. All that would do is assign the static result of that particular call of the function.
While text fields can support a calculated default value, it uses the same functions that are in Calculated columns, which do not support random numbers.
Your best bet is to use an Event Handler, I would recommend ItemAdding over ItemAdded as well. You'd be assigning to properties.AfterProperties["fieldname"] instead of field.DefaultValue, of course.
If you are creating the field through code and setting the field.DefaultValue = Guid.NewGuid(), this will run the Guid.NewGuid() and store the returned Guid as the default
It is the equlivant of running the folowing code:
Guid newGuid = Guid.NewGuid();
string newGuidString = newGuid.ToString();
field.DefaultValue = newGuidString;
I dont know of any method you can use to set the field to generate a new Guid on item creation other than using an Event handler.
It should be posable to genrate a random number using the field.DefaultValue = "RANDBETWEEN(10,20)"; but i have not tested this

Resources