Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to check for duplicates in an Asset Schema object through post-functions

Crystal Rouse June 8, 2024

When saving a custom field's data to the asset schema object, I need to check to make sure it does not already exist.  The attribute is set to be unique.  If the user tries to enter information already existing, there are no error messages returned.  

Is there a way to check for the record in the asset schema as a validator or some other post function before writing the information to the asset schema object?

Any help appreciated!

 

2 answers

1 accepted

1 vote
Answer accepted
Fabian Lim
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 8, 2024

Hi @Crystal Rouse

You will have to use a scripting plugin such as scriptrunner/powerscripts/JMWE to access the objects in your Data Center instance.  I believe there is an AQL you can run with the scripts that should check if an object with the same attribute already exists.

Regards,

Fabian

0 votes
Connie H Johnston June 25, 2024

We ended up using the basic Scriptrunner plugin available with the Validators.  We were using the Summary as the label for the assets object, but wanted to make sure the name was unique.

We had to add a script to include an AQL search to see if there were any objects with the Activity Attribute (label) that matched the Summary entered on the Request Type. Here's what finally worked!

 

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.onresolve.scriptrunner.runner.customisers.PluginModule;
import com.onresolve.scriptrunner.runner.customisers.WithPlugin;
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade;
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade;

@WithPlugin("com.riadalabs.jira.plugins.insight")
@PluginModule IQLFacade iqlFacade
//Get Summary (MMI Activity Name) and add quotes
def activityName = issue.getSummary()toString();
def activityNameAQL = ('"'+ activityName +'"');

//Check Activites Object Type in the MMI Resource Allocation Schema for any objects with an Activty(label)=Summary
def objects = iqlFacade.findObjectsByIQLAndSchema(15,"objectTypeId=229 AND \"Activity\" IN (" + activityNameAQL + ")");

//if there are any objects then return false so the validation will fail
//if there are NO objects then return true so the validation will pass and the new Activity(Suummary) can be added
if (objects) {
return false;
} else
return true;

ScriptRunnerValidation_Create.jpg

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events