Nested class property filter not working MVC5 NonFactor Grid - asp.net-mvc-5

I have integrated NonFactors Grid in my Mvc5 application. Its filtering not working on inner class propery name however it works fine on its own properties. I have one class which is User and this contains School object onto it. This School class a property as Name and I bind it to model as below
columns.Add(model => model.School.Name).Titled("School Name");
columns.Add(model => model.UserName).Titled("User Name");
When I apply a filter on User Name it works perfectly fine but same is not working on School Name. Its giving error in _Grid.cshtml saying Object reference not set to an instance of an object.'
Please refer below.
Can you please guide how to fix it?
Thank You!

Adding null check on column value solved the problem.
columns.Add(model => model.School == null ? null : model.School.Name).Titled("School Name").Filterable(true);

Related

How to conditional object property in Protégé?

I am new to Protégé. I am using version 5.5.0. I want to learn by developing a simple ontology: 2 Classes {Employee, Organization} and 3 Object Properties {WorksAt, HasEmployee, and HasColleague}. I want to declare an object property called "HasColleague" as shown in this such that two entities of Class Employee that work at the same Organization have the HasColleague property. As of now, my object property looks like this but it does not work as I hoped it would. I appreciate your help.

how create new Employee in hybris programmetcally

I am unable to create new user with below code :
final EmployeeModel empl=new EmployeeModel();
empl.setUid("test");
modelService.save(empl);
Also, don't do this: new EmployeeModel();
You should always use the ModelService to create new instance of ItemModel:
modelService.create(EmployeeModel.class)
Using modelService, it will go through any Interceptor that's define for this type and then, could initialize default value for your item. When your using the new operator. It won't set the default value, and can result in the kind of error you are facing.
This code works in an hybris out of the box.
You have probably customized the employee type and added mandatory fields.
Check the error detail, you will probably find out the field you missed.

How to get hidden field value in crm plugin?

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();

Is a newly added field available for BQL to query in database?

Hopefully it is not a stupid question - can I use BQL to query a new field that I just added through customization in database?
I just added a new field to "contract" table through "System->Customization" - I created a project there and added a new field called "ProductCode" (it automatically became "UsrProductCode" in database), and the field does show in "contract" table as well as the "contract template" screen (CT202000) after successful compilation and publish, exactly as I expected, however, I got error:
The type name 'UsrProductCode' does not exist in the type 'PX.Objects.CT.Contract' in file: Code#SOOrderEntry(80)
when I then tried to use this field in a BQL as below:
// Lookup contract template ID
Contract template = PXSelect<Contract,
Where<Contract.isTemplate, Equal<boolTrue>, And<Contract.UsrProductCode, Equal<Required<Contract.UsrProductCode>>>>>
.Select(Base, inventoryCD);
I thought adding new field through customization would automatically make it available for BQL query but it seems I was wrong - what would I need to do in order to make it be able to be used in BQL?
Thanks for your help.
Edited:
Following suggestion from #Jeff Williams, I tried to find out the class definition file related to my customization - the only file I found is "PX_Objects_CT_Contract_extensions.cs", which is under "C:\Program Files (x86)\Acumatica ERP\AcumaticaERP\App_Code\Caches" and the code is very simple as below:
public class PX_Objects_CT_Contract_Extension_AddColumn: PXCacheExtension<PX.Objects.CT.Contract>{
#region UsrProductCode
[PXDBString(30)]
[PXUIField(DisplayName="Product Code")]
public virtual string UsrProductCode{get;set;}
public abstract class usrProductCode : IBqlField{}
#endregion
I also tried to use "PX_Objects_CT_Contract_Extension_AddColumn.UsrProductCode" in BQL and got error during compilation:
'PX_Objects_CT_Contract_Extension_AddColumn.UsrProductCode' is a 'property' but is used like a 'type' in file:
Can somebody tell me what else I need to do to make this new field available for BQL?
It does add it however you cannot reference it as "Contract.Usr..." it would be under something like "ContractExtension.Usr...".
Look at the data class where the DAC extension is and see what that name is. If your BQL is in a different name space you will need to add a reference to the codeclass namespace as well.

Magento: Attribute always returns default value in catalog view, works fine in product view

I've created a new Yes/No attribute for products. I've extended the Product model to do some custom logic and the custom functions are working everywhere.
When I initially tried getting the custom attribute value, I ran into some issue. Magento wasn't loading it for me, so calls to $product->getMyAttributeName() did nothing. In the product views, I got it working with this additional function:
public function getAttrVal($attr_name)
{
return $this->getResource()->getAttribute($attr_name)->getFrontend()->getValue($this);
}
So that worked great when viewing a product on the frontend. It would fetch the assigned value if set, or the default if not.
When I view any Category (grid of all products in that category), the same exact code is being executed. But my getAttrVal() function always returns the default value, even if I've explicitly set this value for my product.
I can't, for the life of me, figure out why the attribute loads correctly in the Product view but the Category view always grabs the default value, despite running the same exact code. Any thoughts?
Because Magento uses an EAV model for its extensible catalog attributes, not every attribute may be carried over onto every page. Try fiddling with the "displayed in catalog" and other related variables on the attribute, and it may fix your problem. If not, say so and we can try other things.
Hope that helps!
Thanks,
Joe

Resources