Hi all so its been a sharp learning curve to get into sugar but its getting quite rewarding now. I've been asked by our tech support team to add an option to the contacts view that will enable them to reset a custom field RegPass__c so that they can easily reset a customer password they use to login into our wordpress support site controlled by sugar.
so i added a new option to the edit menu - Reset Support Site Password (see attached image
code to add this button in ./custom/modules/Contacts/clients/base/views/record/record.php
array (
'type' => 'divider',
),
15 =>
array(
'type' => 'rowaction',
'event' => 'button:reset_user_password:click',
'name' => 'reset_web_password',
'label' => 'Reset Support Site Password',
'acl_action' => 'view',
),
on click this calls a js function callback in /custom/modules/Contacts/clients/base/views/record/record.js
extendsFrom: 'RecordView',
zipJSON: {},
initialize: function (options) {
this._super('initialize', [options]);
//add listener for custom button
this.context.on('button:reset_user_password:click', this.resetUserPassword, this);
},
resetUserPassword: function(model){
// console.log(this);
$.ajax({
url : app.api.buildURL('Contact', 'SupportChangePassword'),
type : "POST",
dataType : "json",
data : JSON.stringify({ "contact_id" : this.model.get('id'), "updated_password" : "magicard123"}),
success: function(data) {
console.log(data);
},
});
},
i tried calling my custom api endpoint which deals with resetting a users password but i get error 500
i tried
model.save({RegPass__c: 'magicard123'});
app.alert.show('update_complete', {
level: 'success',
messages: 'Password reset to Magicard123 and an email sent to the user.',
autoClose: true
});
console.log("Password reset.");
but i dont fully understand the model framework and though that doing this it would already pass the current contact row to model
IS there a better way to achieve what im trying to do or anyone seen a good tutorial to learn about this
thanks