Skip to content

Instantly share code, notes, and snippets.

@anil826
Created July 11, 2019 08:00
Show Gist options
  • Save anil826/a68df2b91fe9488810615a045fd89310 to your computer and use it in GitHub Desktop.
Save anil826/a68df2b91fe9488810615a045fd89310 to your computer and use it in GitHub Desktop.
SyngentaDEPramode
/***********************Dependency List************************* **/
//Dependency JSON
var product1 = {
"Alibaba groß Rapspalette": ["Alibaba groß Rapspalette","01u1o00000OuSj0AAF"],
"One": ["One"],
"test": ["test"],
"Amazon.de Gutschein 25 Euro": ["Amazon.de Gutschein 25 Euro", "01u1w000003n5CaAAI"]
}
var oli_unit_price = {
"Alibaba groß Rapspalette": ["12"],
"One": ["13"],
"test": ["13"],
"Amazon.de Gutschein 25 Euro": ["14"]
}
var order_unit_price = {
"Alibaba groß Rapspalette": ["30"],
"One": ["31"],
"test": ["32"],
"Amazon.de Gutschein 25 Euro": ["33"]
}
// //Repeat group event on adding the record
// formyoula.form_fields["f7e2-c61c-8a3a"].on("input:set:success",function(event_name) {
// console.log('Outside IF===');
// if ( this.get("repeat_value").length ) {
// var repeat_id = this.get("component_id");
// this.get("repeat_value").forEach(function(repeat_group, index) {
// //Get current value for OLI price book id
// var selected_option = _.find(repeat_group, function(element) {
// return element.component_id == "6ee2-acfd-2e89"
// })
// selected_option = selected_option.value;
// //Looop for component data
// _.filter(repeat_group, function(element) {
// //Check if type is Salesforce and null value or no value available
// console.log('Outside IF===');
// /****************Code for the picklist****************/
// //Set the picklist id to text field
// if (element.component_id == "4392-e578-b146" ) {
// //Get the id of selected picklist value
// var selected_picklist_id = product1[selected_option] && product1[selected_option][1] ? product1[selected_option][1] : '';
// console.log(selected_picklist_id)
// element.value = selected_picklist_id;
// }
// //Set the valut to second picklist - Order PBI
// if ( element.component_id == "49b8-df0d-2c75" ) {
// var dependent_picklist = product1[selected_option] ? product1[selected_option][0] : '';
// element.value = dependent_picklist;
// $("#collapse_"+repeat_id+"_"+index+" #component-"+element.component_id+" .input_content").val(dependent_picklist);
// }
// if ( element.component_id == "e255-3f8c-28b5" ) {
// //order Price
// var order_price = order_unit_price[selected_option] ? order_unit_price[selected_option][0] : '';
// element.value = order_price;
// $("#collapse_"+repeat_id+"_"+index+" #component-"+element.component_id+" .input_content").val(order_price);
// }
// if ( element.component_id == "3969-7298-147b" ) {
// //Unit Price
// var unit_price = oli_unit_price[selected_option] ? oli_unit_price[selected_option][0] : '';
// element.value = unit_price;
// $("#collapse_"+repeat_id+"_"+index+" #component-"+element.component_id+" .input_content").val(unit_price);
// }
// })
// })
// }
// })
//Event on change the select list element
formyoula.form_fields["6ee2-acfd-2e89"].on("input:set:success",function(){
console.log('Inside==');
// Check input( $( this ).val() ) for validity here
var selected_option = this.get("value");
//Product/OLI Price book ID
var dependent_picklist = product1[selected_option] ? product1[selected_option][0] : '';
//order Price
var order_price = order_unit_price[selected_option] ? order_unit_price[selected_option][0] : '';
//Unit Price
var unit_price = oli_unit_price[selected_option] ? oli_unit_price[selected_option][0] : '';
//Get id of selected picklist
var selected_picklist_id = product1[selected_option] && product1[selected_option][1] ? product1[selected_option][1] : '';
//Added by pramod
// window.formyoula.form_fields["f7e2-c61c-8a3a"].get('repeat_value')[repeat_index][3].value = dependent_picklist;
// Added by the pramod
// win/dow.formyoula.form_fields["f7e2-c61c-8a3a"].get('repeat_value')[repeat_index][5].value = order_price;
// window.formyoula.form_fields["f7e2-c61c-8a3a"].get('repeat_value')[repeat_index][6].value = unit_price;
//Ended by the pramod
//Set id of select picklist
formyoula.form_fields["4392-e578-b146"].set({"value": selected_picklist_id});
//dependent picklist
formyoula.form_fields["49b8-df0d-2c75"].set({"value": dependent_picklist});
//Order price
formyoula.form_fields["e255-3f8c-28b5"].set({"value": order_price});
//Unit Price
formyoula.form_fields["3969-7298-147b"].set({"value": unit_price});
});
//Event for pre-fill success.
formyoula.form_fields['f7e2-c61c-8a3a'].on('prefill:success',function(){
//Loop for repeat index
for (var repeat_index=0; repeat_index < window.formyoula.form_fields["f7e2-c61c-8a3a"].get('repeat_value').length; repeat_index++ ) {
//Looop for component data
for ( var i_component = 0; i_component < window.formyoula.form_fields["f7e2-c61c-8a3a"].get('repeat_value')[repeat_index].length; i_component++ ) {
//Check if type is Salesforce and null value or no value available
/****************Code for the picklist****************/
if ( window.formyoula.form_fields["f7e2-c61c-8a3a"].get('repeat_value')[repeat_index][i_component].label == "OLI Price book ID" ) {
//Get selected product
var selected_product = window.formyoula.form_fields["f7e2-c61c-8a3a"].get('repeat_value')[repeat_index][i_component].value;
//Check if dependent picklist available.
if ( product1[selected_product] ) {
window.formyoula.form_fields["f7e2-c61c-8a3a"].get('repeat_value')[repeat_index][3].value = product1[selected_product][0];
//Get the select picklist id
window.formyoula.form_fields["f7e2-c61c-8a3a"].get('repeat_value')[repeat_index][4].value = product1[selected_product][1] ? product1[selected_product][1] : '';
//Update UI of the form
$('#collapse_f7e2-c61c-8a3a_'+repeat_index+' #component-49b8-df0d-2c75 .input_content').val(product1[selected_product][0])
//Update UI of the form
$('#collapse_f7e2-c61c-8a3a_'+repeat_index+' #component-4392-e578-b146 .input_content').val(product1[selected_product][1] ? product1[selected_product][1] : '');
}
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment