
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 04:05 AM
I have a requirement where i do not want to get a record inserted into a table if it is allready present.
I have a form as follows:
For each project code i will have to enter 12 month's amount, meaning For '123' project code i need to enter amount for 123-january upto 123-december.
But i dont want to enter 2 entries for 123-january or any month.
I wrote a business rule for this but it doesn't seem to wotk:
BR:
(function executeRule(current, previous /*null when async*/) {
var amt = current.amount;
gs.info(amt);
var month = current.month;
// Add your code here
var gr = new GlideRecord("x_71260_pmo_develo_billing_details");
//gr.addQuery("project_code", current.project_code);
//gr.addQuery("project_status", current.project_status);
//gr.addQuery("year", current.year);
gr.query();
if(gr.addQuery("month","==", month))
{
gs.info("inside IF");
gs.info("You have allready entered PO amount for this month for this project.");
gs.addErrorMessage("You have allready entered PO amount for this month for this project.");
current.setAbortAction(true);
}
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 04:46 AM
Hi Vineetha,
It's easy to do by code( Business Rule).
var gr = new Gliderecord('your table name');
gr.addQuery('ProjectCode',current.projectcode);
gr.addQuery('ProjectName',current.projectname);
gr.addQuery('Projectstatus',current.projectstatus);
.........................................................................
...............// you can add what ever fields u have unique in field
gr.query();
if(gr.getRowCount() > 0)
{
current.setAbortAction(true);
}
This is generic script ,, modify as u want.
if it is correct answer for you , please mark this answer as CORRECT .
regards,
VIPIN MATHEW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 04:07 AM
Why let the user do this? if it always needs to create this, why not make it automatically?
//Göran

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 04:34 AM
This i need for an application, where these values should be entered by a project manager.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 04:18 AM
You mean Amount field will contain Month name also ?
if yes then you can use split by '-' and the take second value of the result and use glideAggregate to take the count if records. if its more than 1 then abort action.
Untested code...
var gr = new GlideRecord("x_71260_pmo_develo_billing_details");
gr.addQuery("project_code", current.project_code); // current.project_code returns sys_id or name? else modify to below
gr.addQuery("sys_id", current.project_code);
gr.query();
var test=gr.amount.split('-');
if (gr.next())
{
if (current.amount.split('-')[1]==test[1])
{
gs.addErrorMessage("You have allready entered PO amount for this month for this project.");
current.setAbortAction(true);
}
}
Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-06-2016 04:34 AM
No amount field does not contain month,there's a separate field for month, scroll to the right of image that i attached.