Home General Discussion

Can I load a controller script from the customspace?

Eric_EvansEric_Evans Member IT Monkey ✭
edited March 2021 in General Discussion

I have a script that will put the affected user and WI info inside a template when using SendEmail (portal task). The issue, I have to edit the controller.js inside the SendEmail task folder which lies outside the customspace folder. Is there a way that I can load this edited js using the custom.js (only when the email task is loaded)?

Answers

  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭

    You mean so you can invoke the Send Email window and your custom code at the same time? IF so, you could invoke its click function.

    $('.cs-form__task--sendEmail').click()

  • Eric_EvansEric_Evans Member IT Monkey ✭

    I mean so the script only loads when the SendEmail form is loaded Much like you do when it's a request offering (loadScript('/CustomSpace/Request-on-Behalf.js',["RequestOffering"]))

  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭

    This might be kind of rough, but my approach would be to hide the original task and add an alternate task. Something like this:

    In custom.css: .cs-form__task--sendEmail {display: none;}

    In custom.js:

    app.custom.formTasks.add('Incident', 'SendMail', function (formObj, viewModel) { 

        $('.cs-form__task--sendEmail').click();

    //your custom code here

      });

  • Eric_EvansEric_Evans Member IT Monkey ✭

    .cs-form__task--sendEmail {display: none;} does not hide the task The bit I am looking to insert is this:


    var everyone = document.querySelectorAll('[class="col-md-6 pad10"]');
    
    
    var neighbor = everyone[3]
    
    
    /* Adds Element BEFORE NeighborElement */
    Element.prototype.appendBefore = function (element) {
        element.parentNode.insertBefore(this, element);
    }, false;
    
    
    /* Adds Element AFTER NeighborElement */
    Element.prototype.appendAfter = function (element) {
        element.parentNode.insertBefore(this, element.nextSibling);
    }, false;
    
    
    /* Typical Creation and Setup A New Orphaned Element Object */
    var NewElement = document.createElement('div');
    NewElement.innerHTML = 'New Element';
    NewElement.id = 'NewElement';
    NewElement.innerHTML = `<input type="button" name="button" value="Insert Ticket Information" onclick="myFunction()">`;
    
    
    /*  Add NewElement BEFORE -OR- AFTER Using the Aforementioned Prototypes */
    NewElement.appendAfter(neighbor);
    
    
    var iframe = document.querySelectorAll('[title="Editable area. Press F10 for toolbar."]');
    
    
    var editframe = iframe[1];
    
    
    var lad = editframe.contentWindow.document.body;
    var attr = document.createAttribute('onfocus');
    attr.value="parent.myFunction()";
    lad.setAttributeNode(attr);
    lad.setAttribute("contenteditable","false")
    

    As Previously stated, the code/script/concept works beautifully. However, I need to call it from the CustomSpace to allow for portal upgrade and so on with nothing breaking.

Sign In or Register to comment.