Set default values when creating contact from lead - customization

I added a few custom string fields using NameValuePair in the Lead form (CR301000). Using the an Action, I create a contact from the lead. I added the same custom fields to my Contact form (CR302000). How can I get the custom values from my lead to my new contact? I tried using the following:
[PXFormula(typeof(Selector<CRLead.contactID, ContactExtNV.usrCROnline>))]
I'm going to have the same issue when I create an account from the lead. Is there a better way to do this instead of using PXFormula?

The Selector parameter for the PXFormula attribute looks like this:
Selector –> Selector<KeyField, ForeignOperand>
KeyField-> The key field to which the PXSelector attribute should be attached.
ForeignOperand-> The expression that is calculated for the data record currently referenced by PXSelector.
That is, in your case it turns out like this:
[PXFormula(typeof(Selector<Contact.contactID, CRLeadExt.usrCROnline>))]
public string UsrCROnline { get; set; }
Adding namespace in the source code using Customization Project Editor

Related

Find the class name of a relation from the instance of a model in ember JS

I have foo an instance of the ember-data model thing. thing.js has the following property :
owner: DS.belongsTo('user')
If I have foo with an empty owner, how can I, with only foo and the 'owner' string, retrieve the value 'user' representing the model of the owner relation?
EDIT: I want to allow my select-relation component to works with relations where the name is different from the class name
It sounds like you have some work to do to finish setting up your relationships. Have a read through this page of the guides.
If the relationships are set up correctly, to get the associated user, you should be able to do foo.owner. This assumes that users are already present in the store. I recommend using the Ember Inspector browser plugin to debug the relationships.
This looks like a use case for typeForRelationship.
In your example you should be able to do something like
store.modelFor('thing').typeForRelationship('owner', store);
If you don't like that approach you can use the belongsTo reference API, where you use the meta data from the relationship to get the type
foo.belongsTo('owner').type
The only thing with that approach is that the type property may not be public API and possible (though unlikely) to change at some point.
It seems I can do the following :
this.get('model').get('_internalModel._relationships.initializedRelationships.'+this.get('relation')+'.relationshipMeta.type')
model being an instance and relation the string of the relation name, it correctly return the model of the relation.
EDIT : a better solution not using private API courtesy from the ember discord :
function getRelatedModelName(record, relationName){
let ParentModelClass = record.constructor;
let meta = get(ParentModelClass, 'relationshipsByName').get(relationName);
return meta.type;
}

Change Display Name of Usr Field After Publish

I am working with a new screen that is using a the DAC and Graph of the Inventory Item table. When I add a field into the form header that is a Usr custom field it has the name that has already been assigned in the a different customization project. How can I change this name in the new customization project. I have tried going through the customize attribute but it does not show up in the fields that I can select. Is there a way to do it through Graph or DAC code or even dynamically? I am just updating the display name not the data type of anything like that. I have tried going through the Label Text property but that does not work.
You could override the DAC field DisplayName attribute in your graph using CacheAttached method.
[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXUIField(DisplayName = "My Display Name")]
protected virtual void DAC_UsrField_CacheAttached(PXCache sender)
{
}

Can I use a Query String to drive personalized content in Sitecore 7.5?

I'm trying to display personalized content on a page IF I have clicked on a specific link on a specific page. My thought was to have a parameter on the link such as:
Go to product page
Then, on "Product Page", hopefully using the rules engine, check if the parameter home exists in the query string. If so, then display a piece of content.
I can't seem to figure out the best way to do this with Sitecore 7.5. Maybe this is the wrong approach.
Out of the box in Sitecore 7.5 there is no rule for using the querystring.
but you can easily create a rule and use with the personalize feature from Sitecore.
See http://blog.martinmiles.net/post/rules-engine-and-sitecore-personalization-based-on-url-query-string-parameters
for a complete description and Example include a link to github with the code
https://github.com/MartinMiles/Personalization
so you would have to have something like this:
public ActionResult Index(string name)
{
Student student = new Student();
student.Name = "John";
if (!String.IsNullOrEmpty(Request.QueryString["name"]))
{
student.Name = Request.QueryString["name"];
}
return View(student);
}
For this example, my controller is named Test. So if I want to call this method I would do ~/test/index, if I do that the student object will contain the name John, however if I do ~/test/index?name=Denis , I will send an object with the name Denis
Here the name will only change when we pass the query string "name" with a value.

How sitecore 7 maps template with class

I have downloaded Sitecore 7 Autohaus demo for learning purpose.
I notice that in Autohaus code, there is a model - Car.
I would like to know how does sitecore know how to map between Car model (code) and CarModel template (sitecore template).
There are a few more steps between the car template and the car object model.
One of the main features of Sitecore 7 is the embedded search capability. When items, created from the car template, are saved, that information is stored in a search index (Lucene or Solr)
The Car model is not mapped directly from the template or the database item but from the search document created.
When you use the LINQ layer e.g.
var index = ContentSearchManager.GetIndex("sitecore_master_index");
using (var context = index.CreateSearchContext())
{
var query= context.GetQueryable<Car>()
.Where(item => item.Seats == 2);
}
Sitecore will execute a search and then take the 'Car' object and populate/hydrate it with the information from the search results by use of Sitecore's DocumentMapper.
This will populate public properties and also indexers of the Car object. The DocumentMapper takes care of casting to and from object types for you (such as DateTime / int etc).
The DocumentMapper will try and map properties with matching field names but you can place attributes on the object properties to help Sitecore map specifically to your objects.
This example tells Sitecore to map the field 'modelkey' to the property ModelId.
[IndexField("modelkey")]
public string ModelId { get; set; }
You can see the LINQ queries used in Autohaus on most of the pages and should be a great resource for learning how Sitecore 7 works.
More info about various parts of Sitecore 7 can be found here: http://www.sitecore.net/Community/Technical-Blogs/Sitecore-7-Development-Team.aspx

django admin filter tweaking

I want to use django's admin filter on the list page.
The models I have are something like this:
class Location(model):
name = CharField()
class Inquiry(Model):
name = CharFiled()
location = ManyToManyField(Location)
Now I want to filter Inquiries, to display only those that contain relation to specific Location object. If I use
class InqAdmin(ModelAdmin):
list_filter = ['location', ]
admin.site.register(Inquiry, InqAdmin)
the admin page displays me the list of all Locations and allows to filter.
What I would like to get, is to get list of only those locations that have some Inquiries in relation to them (so I don't ever get the empty list result after filtering).
How can this be done?
You could create a custom manager for Locations that only returns Locations that have an Inquiry associated with them. If you make this the default manager, the admin will use it.
Only caveat is that you'll need create another manager that returns all Locations and use that in the rest of your app whenever you want to retrieve Locations that don't have an associated Inquiry.
The managers section in the Django docs is quite good, and should be all you need to get this set up.
EDIT:
sienf brings up a good point. Another way to accomplish this would be to define a subclass of django.contrib.admin.SimpleListFilter, and write the queryset method to filter out Inquiries with empty Locations. See https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter