Set Price(field) of Products in opportunities Lines, depending on user role and custom fields in product teplates

Hi.

Hi hope that you can help me with this

I have in Opportunities in related records panels, the lines of the opportunity, whose are related to Products, here, I have a dropdown that is related to ProductTemplates.

When you click in "Elemento de la linea" a search select input is showed, and this field is related to Product Templates.

I want that when the user select that ProductTemplate, in the Product the "Precio Unitario" (discount_price) is seted with some special rules that depends on the role of the current user. 

How can I trigger that event?

I was trying adding a "selection-list.js" in  custom/modules/ProductTemplates/clients/base/views/selection-list/selection-list.js.

But the select list is never render.

({
extendsFrom: 'RecordlistView',

/**
* @inheritdoc
*/
initialize: function(options) {
console.log(options);

console.log("Hello world");
this._super('initialize', [options]);
},
render: function()
{
console.log('GlobalRecordlistView:: render');
this._super('render');
},

})
  • I would create an event onChange in field "Elemento de la linea" which may call an api endpoint. This endpoint is responsible for deciding how to setup the field "Precio Unitario".

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • YEP, 

    I add an event listener to the hidden input of the select 2 with the javascript api

    ({
    extendsFrom: 'CreateView',

    /**
    * @inheritdoc
    */
    initialize: function(options) {
       this._super('initialize', [options]);
       console.log("Record.js");
       this.addEventListener();
    },
    addEventListener: function () {
       $(document).ready(function () {
       try {
       setTimeout(() =>
    {
       let Input= $('input[name="product_template_name"]');
       Input.on('change', e => this.dostuff(e));
     
    }, 1000);
    } catch (error) {
    console.warn(error);
    }
    }.bind(this));
    },
    dostuff: function (e)
    {
    let data = e.target;
    alert(data.value);
    var idTemplate = data.value;
    var productTemplate = app.data.createBean('ProductTemplates', {id: idTemplate});
    AccountsBean.fetch();
     
          }
    })