Read values from Dynamics CRM Lookup Entity form - microsoft-dynamics

I have an entity Property which contains a field that is a lookup to the contact entity
On the Property form, I have displayed the Contact Entity using a custom form defined on the Contact entity. In my javascript code I want to read some field values from the Custom Contact form.
I have tried
Xrm.Page.getAttribute("fieldname")
Xrm.Page.getControl('contactformname').getAttribute('fieldname')
Neither of these work. Can someone help.
Thanks

I am assuming you have created a Quick View Form for Contact that is shown on the Property form.
You can get the value of fields in a Quick View Form using getControl().getAttribute().getValue(). In your case you would access the value of the field as follows, where you substitute the name of the Quick View Form and the name of the field for their real values:
Xrm.Page.getControl("contactQuickFormName_contactQuickFormName_contact_fieldname")
.getAttribute()
.getValue();

Related

Is there any way to determine attribute is select/choice in django model?

Currently implementing searchbox which provides two interface - textbox if required input is not normalized, and dropdown if required input is normalized and is defined with choices param in model, and select class in form.
Current model(partial):
id = models.CharField(args)
submitter = models.CharField(args)
experiment_type = models.CharField(args, choices=<tuple with choices>)
Current form.Meta.widgets for model above:
'id': TextInput(attrs={'id':'exp_id', readonly: ''})
'experiment_type': Select(attrs={'id': 'experiment_type', required=''})
I've currently found that I can retrieve each fields' html snippet by doing str(field), for field in form, and with beautifulsoup or other html parsing library I can find input type(is text field or dropdown(select)), and option values for dropdown.
But it seems too compilcated, and I'm currently guessing that there might be
some way django provides to determine such things.Looking forward, and thanks in advance for any help.

Save the dynamically populated value on dropdown

I'm using wagtail CMS for Django, I want to add a dynamically populated value for a dropdown and save it on the Page model, this is my code:
class MyPage(Page):
domain = CharField(max_length=10, choices=MY_CHOICES)
subdomain = CharField(max_length=10, choices=[('', '------')]
I've got some frontend logic to populate dynamically the options for subdomain, but after I hit save I got: The page could not be created due to validation errors And in the subdomain field: Select a valid choice. [my value] is not one of the available choices.
I can't use ForeignKey to populate subdomain because it depends from an external API service that we're using.
I tried to use a custom field that inherits from CharField with no success, it looks it executes validate method only for the domain field.
If you use the choices argument, you have to predefine the list of possible values. Read the relevant part of the docs (last two paragraphs of that section).
You could omit the choices argument from the model field definition and only render a HTML select tag in the frontend (which is then filled with options dynamically, like you explained).
You could also look into changing the default widget of the CharField to a select tag, like this answer and this part of the docs show.

How to pass parameters to Forms in Sitecore WFFM

Is there a way to pass custom values to a web form in WFFM?
There is a field named "Parameters" under the section "MVC Specific Settings" on "Form" template, setting this field by some values in the content editor and publishing, does not get transfer or populate to the Sitecore.Forms.Mvc.ViewModels.FormViewModel.
For Example:
You can try to get Parameters field value manually by getting rendering datasource item and then parsing Parameters field.

In Django, how to validate a (multiple) cholice field when the choices are added by Javascript?

I have a ChoiceField where the choices are not known at the time the HTML is rendered; they are defined dynamically by the user and added to the form through Javascript, but the validation naturally fails since the selected option is not in the choices attribute (which is just an empty list). I have tried setting the field to a CharField, but then the validator just gets a string value that needs to be converted into a list before it van be used. Ah, and I'd like to avoid subclassing the field class as it's just for one occasion.
I hope this is clear. Any ideas?
Don't subclass the field class but override the clean_<yourfield> method in your Form class. See the docs here.

How to make fields readonly while updating

I have a form. Once the form is filled I don't want the user to change anything in the form.
But the user can see the values. Meaning all the fields are non editable. I can do this by using instance method but this does not help in foreignkey.
Depends on what you mean "once the form is filled".
If it's an html form post, just render a new html page with simple text and values of the submitted form.
If the post-back was an ajax call, you can change the CSS-styling of the elements for example and disable the submit button or erase the whole and substitute the values that you get back from ajax request.
There is no "editable=False" property on html input elements btw.
you can use readonlyAdmin