Date validation of other saved document

i add custom field on Event Doc link to customers i need to make some thing like relation between customer and the date on Event doc
so if i safe the event for specific customer to be not allow to set the same customer on new event if its within the same date

Add validation for it. On validate check whether the event is created for the same customer on the same date?

Dear @Sangram
Thanks for your help
but i’m not understand what you mean about validation for it i need when create new event system check if the customer have another event in the same date

Thanks in advance

@Alaa_Badri

you need to write a script for it. Frappe has provision to write custom script.
Check

Custom Script Examples
and
Client side scripting

Dear @Sangram
I know about custom scripts and i have some on my system but i’m asking for the script idea to how do the case i mentioned above

Thanks

Dear @Sangram
Any update

you can check whether an event is already available for the customer (for the particular date). If present the throw message - Event already exists in the system for same customer and date.

e.g.

validate: function(frm) {
	frappe.call({
		method: "frappe.client.get_value",
		args: {
			doctype: "Event",
			fieldname: "name",
			filters: { 
				customer: frm.doc.customer,
				date: frm.doc.date
			},
		},
		callback: function(r, rt) {
			if (r.message.name) {
				frappe.throw(__("Event {0} is already exists.", [r.message.name]))
			}
		}
	});
}

you can add your filters to check event. Do necessary changes in script as per your need.

Dear @Sangram
Thanks for your help
but i got this error

SyntaxError: Unexpected token (
    at Class.setup (http://erp.shiftits.com:81/assets/js/form.min.js:2621:18)
    at _f.Frm.setup (http://erp.shiftits.com:81/assets/js/form.min.js:172:22)
    at _f.Frm.refresh (http://erp.shiftits.com:81/assets/js/form.min.js:439:9)
    at Class.load (http://erp.shiftits.com:81/assets/js/form.min.js:87:33)
    at http://erp.shiftits.com:81/assets/js/form.min.js:82:7
    at Object.callback (http://erp.shiftits.com:81/assets/js/desk.min.js:6573:6)
    at Object.callback [as success_callback] (http://erp.shiftits.com:81/assets/js/desk.min.js:1210:16)
    at _ (http://erp.shiftits.com:81/assets/js/desk.min.js:1234:34)
    at Object. (http://erp.shiftits.com:81/assets/js/desk.min.js:1330:4)
    at i (http://erp.shiftits.com:81/assets/frappe/js/lib/jquery/jquery.min.js:2:27151)  

and the date doc in the event called starts_on and how the code will compare the current date with already saved dates before and filter it with customer

thanks in advance

Dear @Sangram
Any Update

@Alaa_Badri

check your syntax. seems like a syntax error in your code.

Dear @Sangram
Thanks for your support
this my code i don’t know where is the error

validate: function(frm) {
frappe.call({
method: “frappe.client.get_value”,
args: {
doctype: “Event”,
fieldname: “Client”,
filters: {
customer: frm.doc.client,
date: frm.doc.starts_on
},
},
callback: function(r, rt) {
if (r.message.name) {
frappe.throw(__(“Event {0} is already exists.”, [r.message.name]))
}
}
});
}

Dear @Sangram
Any update

Check this,

validate: function(frm) {
		frappe.call({
			method: "frappe.client.get_value",
			args: {
				doctype: "Event",
				fieldname: "client",
				filters: {
					"customer": frm.doc.client,
					"date": frm.doc.starts_on
				}
			},
			callback: function(r, rt) {
				if (r.message.client) {
					frappe.throw(__(“Event {0} is already exists.”, [r.message.client]))
				}
			}
		});
	}

Hope you have Event doctype with field client, customer, and date. If it does not work then try to check fields and filters.

Dear @Sangram
Thanks for your response
but i still got the same SyntaxError

Dear @Sangram
Any update

Syntax should be like,

frappe.ui.form.on('Event', {
	validate: function(frm) {
		// Script
	}
})

Dear @Sangram
i try the below code but not working properly do you have any suggest

frappe.ui.form.on("Event", "validate", function(frm) {

    frappe.call({
            method: "frappe.client.get_value",
            args: {
                    doctype: "Event",
                    fieldname: "name",
                    filters: {
                facilitator: frm.doc.facilitator,
                starts_on: frm.doc.starts_on,
                ends_on: frm.doc.ends_on
                    }
            },
            callback: function(response) {
                 var facilitator = response.message;
                 if (facilitator) {
                      frappe.msgprint("Same facilitator with the Same Time Period is Already Exist in Record.");
             validated=false;
                  return false;
         
                 }
            }
    });
    });

What did you get in response?

Dear @Sangram
thanks for your reply
the code only checks the validation in the first time and then if I change the date to be in the same period it’s not validated for example if I have an event from 11 July to 13 July and I make a new event from 12 to 13 for the same facilitator its save normally and didn’t make any validation while the facilitator has an event from 11 to 13