Updating Transaction Currency On Form Doesn't Update Custom Money Currency Symbol - dynamics-crm-online

I'm creating an empty shell of a lead on a custom web page, then redirecting the user to the newly created lead. The TransactionCurrencyId on the lead is empty on load, and in the OnLoad event, JS is setting the TransactionCurrencyId, and then populating the custom Money field. Upon setting the money field, the following alert is being thrown:
A Currency is required if a value exists in a money field. Select a
currency and try again.
Manually clearing the TransactionCurrencyId, and then re-selecting the TransactionCurrency allows the user to manually populate the value.
Shouldn't the Transaction Currency be set by default, and how do I set the TransactionCurrencyId in order to set the Custom Money Currency Symbol?

I was able to get around this be calling this on the custom Money attribute in the onLoad, before actually setting the value:
att.$2_2.setCurrencySymbol("$")
Of course this is unsupported and not an ideal solution...

Related

Using ajax in prestashop custom module, retrieve data from an input field date to a module's FrontController for exploitation and SQL query afterwards

I need your help to understand how to retrieve the data from the product page form (product.tpl) sent by the 'add to cart' button (product-add-to-cart.tpl include).
Indeed, I would like to retrieve the value of a datepicker field, added under the entry dedicated to the quantity of the product page,
in order to save it in the ps_cart_product table.
Despite my research in the cart class and its controller, I can't do it. How to retrieve the value of an entry in the home page of a product?
A null date (0000-00-00) is however well recorded in our new columns date_retrait in ps_cart_product, we manage to recover it as you can see on a screen, but not to record it correctly.
Where can I call $_POST or REQUEST from the input datepicker name = date_retrait
(here it is 2022-07-24 but this is only a test, modified directly in the DB, normally it displays 0000-00-00)
I understood that I had to use Ajax (mymodule\/controller\/front\/ajax.php)
But I don't understand all the steps, what should I add/modify and especially: where (which files with path)?
[product_tpl][1]
[cart_popup][2]
[add to cart][3]
[ps_shoppingcart_js][4]
[1]: https://i.stack.imgur.com/MwLPS.png
[2]: https://i.stack.imgur.com/LjpMe.png
[3]: https://i.stack.imgur.com/3P4Y2.png
[4]: https://i.stack.imgur.com/z0eb4.png

Joomla 2.5 - custom registration field not remembering values

Im using custom profile plugin found at http://library.logicsistemi.it/images/joomla/plg_user_testprofile.zip
I have created several fields, both, optional and required and they all work. But there is a tiny problem.
When I enter some value in that custom fields and submit the form it can happen that some fields dont pass validation (which is good). However values entered are cleared and I must fill all the fields from the beggining.
Demo: http://goo.gl/eH1G2
Enter some (not all) data under the 'legend' named User Registration
Enter some (not all) data under the 'legend' named Company
Informations
Press Register button
Error message will pop in. -
Data entered in the User Registration will be saved
Data entered in the Company Informations (which are custom fields)
will not be saved.
If all required fields are entered, form will submit data to database
(which is ok).
I want that data in the Company Informations are saved, so users dont have to type in all over again.
The problem in your demo is on the template you are using.
For some reason it gives Javascript errors. These errors blocks the Javascript client side validation and your form is submitted with invalid data.
If you want only server side validation you can modify the onContentPrepareData function in your plugin by loading posted information from the user state. To do this you have to permeform a different action when user_id is not set under "Merge the profile data." comment.
I think next week I will write a new tutorial on http://library.logicsistemi.it to explain this. For now try to fix your Javascript code.
Regards

Magento Price Alerts - Trigger on Tiered Price change

I've never set a store up to use Price Alerts before, and now that I've gone through and gotten it to work, it appears as though the alert is only triggered when a product's 'Price' attribute changes.
This is nice, but what about tiered pricing? Looking through the ProductAlert core module, I am not sure where this attribute is being filtered.
I'm guessing that an additional model, say 'productalert/tierprice' will need to be created, followed by a new method in Observer.php, likely _processTierprice(). Just not sure if this concept is correct... could use a little guidance.
Thanks!
This shouldn't be too difficult; lots of options (it's Magento, after all)!
I'd add new methods to deal with tier price alerts. For products with tier pricing, you'd need to capture the relevant tier data along with the final price (either in a new table or in new columns on the existing product alert table). The alerts are sent out via scheduled job. So, in a nutshell (overrides where necessary):
Alter the product alert schema as necessary, and amend the frontend form fields to suit
In the overridden Mage_ProductAlert_AddController add a tierPriceAction() method to process the alert subscription, or adjust its existing priceAction() to handle the data being posted in / tier condition
Override Mage_ProductAlert_Model_Observer as needed; I'd include a _processesTierPrice method() similar to _processPrice().
Add a resource model method to get the tier-related prices
Add a tier price email block and template (reference Mage_ProductAlert_Block_Email_Abstract)
Profit!
As a reference for your price logic, see Mage_Catalog_Model_Product_Type_Price.

MS CRM - getting the field that caused a form save

I have a MS CRM 4 form where when certain fields are changed, I need those fields to be written to an excel sheet.
So, I edited the form field onchange event to call crmform.save() which triggers a plugin to run that writes the field value to a named range (1 cell) of an excel sheet.
However, I don't know which field caused the save. Is there a way to get that information? (Not all fields on the form need to go to the excel sheet)
If I use this: DynamicEntity target = (DynamicEntity)Context.InputParameters[ParameterName.Target];
I can look at specific fields, but I have no way of knowing which ones changed.
Any suggestions?
It's my experience that only the changed fields will have value (in the DynamicEntity) when you update an entity. So let's say you have an entity with a FirstName and Lastname. If you only change the LastName and save. The LastName will have a value however FirstName with be null (unless you have som javascript code that forces the FirstName to be submitted).
If your plugin is triggered on the Pre-Event of the Update on your entity, you should be able to compare the IPluginExecutionContext.PreEntityImages to your DynamicEntity that you've fetched from the Target.
Or if your plugin is triggered on the Post-Event of the Update, you should be able to compare the IPluginExecutionContext.PreEntityImages with IPluginExecutionContext.PostEntityImages.
Looks like you are already going a different way, but another suggestion is to create a hidden field - "FieldThatChanged." In your field on-change javascript, set that field to the name of the field that changed, then access that in your plugin.
Yep, totally changed the way I approached this. I'm using jquery in an iframe to pass all the exact fields (name/value pairs) I want to a method of an ASPX file running in the ISV folder that takes the neccesary action. Thanks for the suggestions all!
I recommend using the Pre and Post Images as suggested by #Forgotten Semicolon. And in addition set the Filtering Attributes so the Plugin is triggered only on the change of the fields you care about.

Dynamics CRM error "A currency is required if a value exists in a money field" after converting Activity to Case

We have a Dynamics CRM 4.0 instance with some custom attributes of type "money" on the Case entity and on all Activity entities (Email, Phone Call, etc.) When I use the built-in "Convert Activity to Case" functionality I find that the resulting Case does not have a Currency set, even if the Activity it was created from does have it. Whenever the case is opened the user then gets this JavaScript error:
A currency is required if a value exists in a money field. Select a
currency and try again.
This is extremely annoying! How do I fix it? Is there any way I can set the currency? It needs to be done synchronously, because the Case is opened immediately when it's created from an Activity. So even if I started a workflow to set the currency the user would still get that error at least once. Alterntatively, can I just suppress the warning somehow? I don't really care about setting the Currency, I just want the error gone.
I guess this code will be helpful for next person who have a same problem.
I spent whole day to figure out what I did below.
There are two steps involved here:
set default currency
set currency symbol for the money field.
Here is the code sample.
var currency = crmForm.all.transactioncurrencyid;
if (currency.DataValue == null) {
var lookupData = new Array();
var lookupItem= new Object();
//Get transaction currency value from :
select **TransactionCurrencyId** from MSCRM.dbo.TransactionCurrency
lookupItem.id = '{The GUID that you get from the SELECT statement above}';
lookupItem.typename = 'transactioncurrency';
lookupItem.name = 'US Dollar';
lookupData[0] = lookupItem;
currency.DataValue = lookupData;
//set default currency symbol for all the Money field.
var defaultSymbol = '$';
for(var i=0; i < crmForm.all.length ; i++) {
var oCtr = crmForm.all[i];
if(!IsNull(oCtr.IsMoney) && !oCtr.IsBaseCurrency)
{
oCtr.CurrencySymbol = defaultSymbol;
}
}
}
This annoying issue was resolved on my system by discovering the transactioncurrencyid used for US dollars and then updating the transactioncurrencyid column in the entity's database table for all the existing entity records. After doing this I was able to add money values on the entity form with no further problems. Not sure if this solution would be ideal for everyone, but as I did not want to write code to do this and felt I shouldn't have to since if I added money attributes to a newly defined entity it didn't require writing code on my part to populate the transactioncurrencyid field - it just did it by default. So in summary, this problem only seems to occur if the the money fields are added to an existing entity that has existing data associated with it.
set default currency in Personalize Workspace, General tab
NEW records will use this currency
For EXISTING records (before money field(s) added) use Advanced Find to find records with NO currency value, then use Bulk Edit to set currency
You might want to check out this article CRM 4 Currency Calculations by Mitch Milam
Update : After googling around, i found out that you might need to set the transactioncurrencyid lookup somewhere. So in your case, it might be onsave or inside the execution of the workflow codes. I read it from here Error: Assign a decimal value to CRM 4.0 money field using Javascript
If your form has a money field on it, CRM needs to know which currency to use. Verify that a default currency is set in your user preferences (Personalize Workplace from the main page, then the General tab). That is, each of your users will need to have a default currency set.
I have also been able to work around this issue by adding the currency field to the form, defaulting it to US dollars, and then hiding the field. If memory serves, though, this isn't ideal because the US dollars currency is a record in the system and can have different GUIDs in different environments.
Since this thread came up in my Google search when I was looking for a solution to this problem for CRM 2011, I thought I'd add my blog article explaining how to set the default currency lookup in the Onload of a CRM 2011 form using JavaScript, JSON and OData.
http://crmscape.blogspot.com/2011/03/crm-2011-set-default-transaction.html
I agree with Hadi Teo that you need to set the transactioncurrencyid. Its been awhile since I ran across this - so here is what I think I remember.
If you create a new entity with a money field populated the transaction currency will be set.
If you update an entity, the transaction currency field will not be set.
I haven't used the Activity to Case function so I'm not all that sure what it does. One thing you can do as a work around is to add the transactioncurrencyid onto the form. Then you can set it before you modify your Case.
The other would be to default the currency in code. There are two places to determine the default currency. First off of the user settings. Second (if that is null) off of the organization settings.
Fix for this problem
1. Add the base currency field also to the form.
2. Untick the "visible by default option" of the base currency field.

Resources