Adding tasks in draft to OmniFocus, using the tag for OmniFocus project

For many years I am using a script to add a draft line starting with @ as a task to OmniFocus. I now want to use the drafts tag as Project in OmniFocus. I cannot get it working. Can somebody help me? Very appreciated. Below the script I am using:

// Start every line with a @ to denote it as a task

const taskPrefix = "@";

// Function for removing the task prefix
function removeTaskPrefix(s) {
  var f       = (taskPrefix),
      r       = "",
      re      = new RegExp(f,"g"),
      matches = s.match(re);

  if (matches) {
    return s.replace(re,r);
  }
}

// Function to perform the callback url
function doCallbackURL(url, params) {
  var cb = CallbackURL.create();
  cb.baseURL = url;

  for(var key in params) {
   cb.addParameter(key, params[key]);
  }

  var success = cb.open();
  if (success) {
    console.log("Event created");
  } else {
    console.log(cb.status);
    if (cb.status == "cancel") {
      context.cancel();
    } else {
      context.fail();
    }
  }
}

// Scan for the task prefix in the draft
var lines = draft.content.split("\n");

for (var line of lines) {
  // If the line includes the task prefix, 
  // we remove exclude it from the final notes
  if (line.startsWith(taskPrefix)) {

    // Remove the trigger from the line
    var task = removeTaskPrefix(line);
    var alink = draft.permalink;
    console.log(task);
    console.log(alink);
    
    // OmniFocus URL Action
    doCallbackURL("omnifocus:///add", {"name": task, "project": draft.tags[0], "note":"Title and link to note: " + draft.displayTitle + ": with link: " + alink, "autosave": true});
    
 }
}

Could you provide details on what behavior you are seeing? Is the action generating any errors? Is the task created but not with the project you want to be assigned? etc.

Thanks for your interest and question. It is not using the tag to add it to OF as project, with no error message, but OF task is being created

I just tested this script with OmniFocus (3.15.4) on Mac, and it worked fine and the task was created with the project assigned based on the tag assigned to the draft.

What version of OmniFocus are you using?

If you open copy and paste this URL into Safari, and open it, does it create a task properly with the “Test” project assigned?

omnifocus:///add?name=TaskName&project=Test