Show only those items which are not selected

In Quotation Items are added as table, so while adding rows in item table how can I restrict to show only those items which are not selected in above rows.

For example, if I am creating a quotation I have entered all details and when I am adding items at first it is showing all the items in dropdown, I have selected one item and if I am adding another row it again shows all the items in dropdown.

My requirement is that it shows only those items in dropdown which are not selected for that quotation or records.

Please reply me soon as it is very urgent.

Thanks in advance,
Tanveer

Hi @tanveer,

Create the custom script for Quotation and add the filter to Quotation Item's item_code field to filter out the items that are already added.

e.g.

cur_frm.fields_dict.items.grid.get_field("item_code").get_query = function(doc) {
	items = $.map( cur_frm.doc.items, function(item,idx) { return item.item_code } )
	added_items = items.join(",")
	return {
		filters: {
			"item_code": ["not in", added_items]
		}
	}
}

The above script will filter out the already added items.

Thanks, Makarand

1 Like

where to add this custom script

Go To Custom Script > New Custom Script

select Doctype as Quotation and place your script in script field

Please refer the ERPNext manual for custom script

Hi Makarand,

Tried this now but it is not filtering the items.

Thanks,
Tanveer

reload the application and try again

done but still not working :frowning:

the script you sent is complete or I have to add something in this as this is not working.

Hi @tanveer! Can you please send a screenshot where you have put your custom script and lets try to check it for errors. :slight_smile:

Hi,

This is my script here.

@tanveer

please check the filters.

it should be

filters: {
	"item_code": ["not in", added_items]
}

instead of

filters: {
	["item_code","not in", added_items]
}

Done but it is still not working

@tanveer,

It working on my setup can you share the screenshot or you script ?

Hi @makarand_b , @creamdory

Have you seen my script please tell me that where I am wrong as this is not working.
Waiting for the response.

Thanks,
Tanveer

Hi @tanveer! Still testing on my side. Tried the given script but not working.

Yes it is not working on my side also please help me out on this.

Still waiting for the solution. Please help me on this as this is very urgent.

Thanks in Advance,
Tanveer

Hi tanveer,

I wish I could help you, but my javascript skills are not great yet. I wanted to let you know that this open source community is VERY helpful and kind, but for anything you need URGENTLY I highly recommend hiring a freelancer or a service provider if you’re not a programmer yourself. Otherwise be prepared to wait and when people have time someone will usually find a solution.

Good luck!

https://community.erpnext.com/service-providers