Workflow with email validation in the input channel with online from

Hi, I'm trying to work with the workflow to validate my email input field 

By using the “JavaScript Editor” and defined new workflow to get the online form when it's summited in order to validate the email field and refuse to create a ticket if email does not respect my REGEX

// Regular expression to validate email format,  var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;  

But I'm new with YouTrack and I'm not sure whish rights steps I need to flow   

0
3 comments
Official comment

Hi!

I'm Sergey from the YouTrack team.

Firstly, if you are not familiar with the workflow functionality, please refer to our tutorial. It covers the basics you need to know to start.

To prevent an action, one can use the workflow.check() method. As for checking issue or ticket creation, you can use the becomesReported property of the Issue entity. 
 

const entities = require('@jetbrains/youtrack-scripting-api/entities');
const workflow = require('@jetbrains/youtrack-scripting-api/workflow');

exports.rule = entities.Issue.onChange({
  title: 'Forbid issue creation',
  guard: (ctx) => {
    return ctx.issue.becomesReported
  },
  action: (ctx) => {
    workflow.check(<your condition that must be met>,
      'You cannot create an issue');
  },
  requirements: {}
});

Hi Sergey Merzlov your answer is appreciated and rely help full 

and I didn't know that workflow.check exist and I'm glad that pointed out.

I'm trying to get the source of creation ticket (FeedbackForm or MailboxChannel) by using ctx.issue.channel but I have face this error message: “Processing Issue 3-159: Cannot resolve property FeedbackForm.name” and look like my “ctx.issue” created from the FeedbackForm  not contain the object “channel”? 

I don't understand why if you can help with:

const entities = require('@jetbrains/youtrack-scripting-api/entities');
exports.rule = entities.Issue.onChange({
 title: 'Log creation channel of issues',
 guard: (ctx) => {
   return ctx.issue.isNew; // Ensure the rule runs only when the issue is new
 },
 action: (ctx) => {
   console.log(JSON.stringify(ctx.issue, null, 2));
   ctx.issue.channel.name
   
    console.log(`Issue created via channel (${ctx.issue.channel}): ${ctx.issue.id}`);
    if (ctx.issue.channel === 'FeedbackForm') {
      console.log(`Issue created via FeedbackForm: ${ctx.issue.id}`);
    } else if (ctx.issue.channel === 'MailboxChannel') {
      console.log(`Issue created via MailboxChannel: ${ctx.issue.id}`);
    } else {
      console.log(`Issue created via unknown channel (${ctx.issue.channel}): ${ctx.issue.id}`);
    }
 },
 requirements: {}
});

 

0

Hello,

Thank you for your response.

It appears that you've encountered this bug: JT-82509 Workflows: issue.channel property doesn't work. It has already been fixed and is pending release. Please feel free to vote for this issue. Your vote helps us measure how many customers encounter this problem, and you'll also be subscribed to the issue’s notifications. To vote, sign in to JetBrains YouTrack and click the thumbs-up icon.

I apologize for any trouble caused. If you have any questions, please let me know. 

0

Please sign in to leave a comment.