Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

How to restrict UI script to specific projects


#1

Hi,

what do I need to add to a UI script, so that it only affects a specific project ?

While I test a script, it should only be useable/viewable from the test project and not from any of the production projects.

Is this possible ?
Thanks


[UI Script] Make Estimate field required
#2

Hello Andreas,

Thanks for your posting. You can limit UI scripts to select projects via the UI script context:

http://docs.gurock.com/testrail-custom/uiscripts-introduction#context_information

If the UI script runs in a project context, you have access to a uiscripts.context.project in your UI scripts and this can be used to check for the name or ID of a project:

if (!uiscripts.context.project || uiscripts.context.project.id != 10)
{
    return; // Only apply this UI script to project with ID 10
}

I hope this helps!

Cheers,
Tobias


#3

that was it - thanks for the answer


#4

You are welcome!

Cheers,
Tobias


#5

Hi,
Could this script be changed so that instead of looking for a specific id, the script instead looked for the value located in the announcement field? There will be multiple projects that I want to influence but it would be easier if users creating the project could just be instructed to add specific verbiage in the announcement field.

Thanks

if (!uiscripts.context.project || uiscripts.context.project.id != 10)
{
return; // Only apply this UI script to project with ID 10
}
[/quote]


#6

Project announcement is not available in uisripts, you shall make an api call to get it. So solution will not be fast and smooth. But you can use a project name for this. Just add some #hashtag and check what it presents in project name.

if (!uiscripts.context.project || uiscripts.context.project.name.indexOf(’#hashtag’) === -1)
{
return; // Only apply this UI script to project with #hashtag
}