How to auto add a customer to customer master if entry does not exist?

Hello,

In our CRM when a user is entering an Incidence the user has to enter Customer name.

This customer name is autocomplete (looked up) from customer master and if the customer name typed exist in customer master that customers data is fetched and necessary fields are populated.

But if the customer name entered does not exist in customer master then that customer’s data as entered in Incident page should automatically get added to Customer master.

How can we do this?

@YogiYang this configuration is not yet available in radsystems. but radsystems has the autocomplete feature for fields, when configured suggestions will be made to the user with available data from a database table that the user can either select from or chose to save what has been typed.

1 Like

@willvin,

Thanks for your reply.

In this case can I detect if the auto complete field contains data from DB ?

I mean if I can find out whether what the user has typed in the auto complete field does not come from database then I think I can write code in BeforeAdd event to first save the data entered by user to a table and then extract the ID of the newly inserted record and update the field in form before it gets saved.

Can we do something like this?

If yes are there any tutorial explaining the exact steps.

@YogiYang you can use the Action After Add in Page Events to do a query to check the value in the DB using the value submitted.

1 Like

Hi,
I am facing the same problem. I need to check the data whether exists or not beforeAdd through below code but cannot.

 
        $data = DB::table('master_plan')->where('batch_no', Request $request->batch_no)->where('storage_condition', Request $request->storage_condition)->first();
      
        if ($data != null) {
       
                exit;
            
            } else {
       
              }

My question is how can I get data from submit form field here (Request $request->batch_no). In case of afterAdd event I can use $record->batch_no but this time what should I use? Please help.

Thanks

@phrmst from the code above, I can see you are rather defining the request, instead of accessing it, which is wrong. It should look like below.

$data= DB::table('master_plan')->where('batch_no', $request->batch_no)->where('storage_condition', $request->storage_condition)->first();

if ($data) {
     return true;
} else {
       
}

@YogiYang late reply but i hope it will help you!if you are using the vue framework! i suggest doing this!

write an endpoint that is parametrized! you need to write params that will be checking for a record in the database! now! go to your frontend and now in the add page add custom code in the mixins under watch function ! this will ensure that the record is checked in the database as you type! instead of having to first click on the add button!
now in this code you can be checking if a record is available if not display a notification saying or asking do you want to add this record to the database! now you can either use the button to add thats created by radsystems or you can create yours in the methods() to add! this way you dont have to use page events which need you to first click on the add button! i hope this helps

1 Like