1

I'm having problem passing some complex data in a call, one type is HTML, another one is stringify Json.

REQ_Description = HTML
REQ_Services = JSON.stringify(SomeData) 

Here is my code

SERVER



 Interface

         [WebGet(UriTemplate = "InsertPedidos/{requestId}/{categorie}/{projectType}/{sla}/{possibleDate}/{desireDate}/" +
                                         "{desireJustification}/{services}/{description}/{workflowState}/{tempId}", 
                                         BodyStyle = WebMessageBodyStyle.Bare,
                    ResponseFormat = WebMessageFormat.Json)]
                int InsertPedidos(string requestId,
                    string categorie, string projectType, string sla, string possibleDate, string desireDate,
                    string desireJustification, string services, string description, string workflowState,
                    string tempId);

Implementation

 public int InsertPedidos(string pid, string requestId,
            string categorie, string projectType, string sla, string possibleDate, string desireDate,
            string desireJustification, string services, string description, string workflowState, 
            string tempId)
        {
            var data = new LinqToRequestsContext(Elevate.RequestsUrl);
            var ped = data.GetList<FDM_MAINREQUESTSMAINREQUESTS>("FDM_MAINREQUESTS");

            ped.ScopeToFolder(_folder, false);

            var insert = new FDM_MAINREQUESTSMAINREQUESTS()
            {
                REQ_RequestID = double.Parse(requestId),
                REQ_Categorie = double.Parse(categorie),
                REQ_ProjectType = double.Parse(projectType),
                REQ_SlaOnDate = int.Parse(sla),
                REQ_RequestDate = DateTime.Now,
                REQ_PossibleDate = DateTime.Parse(possibleDate),
                REQ_DesireDate = DateTime.Parse(desireDate),
                REQ_DesireJustification = desireJustification,
                REQ_Services = services,
                REQ_Description = description,
                REQ_Worflow_State = int.Parse(workflowState),
                REQ_Origin = 0,
                Title = tempId,
                REQ_CRU_DateCreated = DateTime.Now,
                REQ_CRU_UserCreated = SPContext.Current.Web.CurrentUser.Email
            };
            ped.InsertOnSubmit(insert);
            data.SubmitChanges();
            return 1;
        }

Client Side

function InsertOrUpdatePedido(id, how) {
    $("#img_Progress").show();

    var $treemain = $("#tt"); // the source tree
    var data = $treemain.tree("getData", $treemain.tree("getRoot").target);
    var jdata = JSON.stringify(data);

    if (how > 0) {
        this.litem = list.getItemById(how);
    } else {
        var formData = {
            requestId: id,
            categorie: $("#sel_categories option:selected").val(),
            projectType: $("#sel_projecttype option:selected").val(),
            sla: $("#tipoSla").val(),
            possibleDate: $("#dataPrevista").val(),
            desireDate: $("#dataDesejada").val(),
            desireJustification: $("#justificacaoPedido").val(),
            services: jdata,
            description: $("#weditor").Editor("getText"),
            workflowState: "1",
            tempId: tempid
        };


        JSON.stringify(formData);

        jQuery.ajax({
            cache: false,
            type: "GET",
            url: "/_vti_bin/APP/Requests.svc/InsertPedidos",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: formData,
            success: function(ret) {
                if (ret === 1) {
                    MessPopups("s", "Pedido efetuado corretamente");
                }
            }
        });
    }
}

Can someone give me a clue? i tried to decodeURI() for complex fields because is passing "%2%2....", tried also to stingify DATA, no luck. Is there any other way? I think I wrote the code to complex and not "KISS".

I´m Stuck

Thank You Joao

Deenadhayalan Manoharan
  • 5,436
  • 14
  • 30
  • 50
Joao Livio
  • 89
  • 1
  • 1
  • 13

0 Answers0