Home General Discussion

SR - Custom Task to create ChangeRequest from Template and map the SR as related Workitem

Kevin_BaierKevin_Baier Customer IT Monkey ✭

Hi Community


Is there are way to create a CR from a SR-Form with a custom Task, with a specific template

And map the SR to the CR as related Workitem? In one Step?


Best Regards

Kevin

Best Answer

Answers

  • Kevin_BaierKevin_Baier Customer IT Monkey ✭

    Okey i modified the "Copy CR" Skript from a other Guy:

    Only the ID of the template in the last Line Needs to be changed to the Template ID you need

    /******************************/
    /*Copy CR */
    /******************************/
    app.custom.formTasks.add('ServiceRequest', "Copy CR", function (formObj, viewModel) {
     CopyCR();
     });

    function CopyCR () {

        function CopyChangeRequest (templateId, vm_SR) {
            //Logged in User Id
            var uid = session.user.Id;
            //console.log(uid);
            $.ajax({
                url: "/api/V3/Projection/CreateProjectionByTemplate",
                data: {id: templateId, createdById: uid},
                type: "GET",
                success: function (data) {
                    console.log(data);

                    //Get the CR information and copy it to the new CR
                    data.Title = vm_SR.Title;
                    data.Description = vm_SR.Description;
                    data.RelatesToWorkItem = [{
                        ClassTypeId: vm_SR.ClassTypeId,
                        BaseId: vm_SR.BaseId,
                        Id: vm_SR.Id
                    }];
                                                                
                    //console.log (data)
                    var crId = data.Id;
                    var strData = { "formJson":{"current": data }}
                    $.ajax({
                        url: "/api/V3/Projection/Commit",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: JSON.stringify(strData) ,
                        success: function (data2) {
                            window.location.href = window.location.protocol + "//" + window.location.hostname + "/ChangeRequest/Edit/" + crId
                        }
                    });                                
                }
            });
     }

     CopyChangeRequest("480f1b54-a316-074c-f3a9-2165ea1ed4c4", pageForm.viewModel);
     
     }


    Is there are way that the CR will not be created directly, that the Users are able to add a reviewer in a activity and Change something?

Sign In or Register to comment.