Example #1
0
        protected override void Execute(NativeActivityContext context)
        {
            if (SnowBaseURL.Get(context) == null)
            {
                throw new ArgumentException("SNOW Base URL");
            }

            if (UserName.Get(context) == null)
            {
                throw new ArgumentException("UserName");
            }

            if (Password.Get(context) == null)
            {
                throw new ArgumentException("Password");
            }

            snowDetails = new ServiceNowProp(SnowBaseURL.Get(context), UserName.Get(context), new NetworkCredential(String.Empty, Password.Get(context)).Password);


            if (Body != null)
            {
                //scheduling the execution of the child activities
                // and passing the value of the delegate argument
                context.ScheduleAction <ServiceNowProp>(Body, snowDetails, OnCompleted, OnFaulted);
            }
        }
Example #2
0
        protected override void Execute(CodeActivityContext context)
        {
            ServiceNowProp snowDetails = (ServiceNowProp)context.DataContext.GetProperties()["snowDetails"].GetValue(context.DataContext);

            var userName       = snowDetails.UserName;
            var password       = snowDetails.Password;
            var snowInstance   = snowDetails.SnowInstance;
            var incidentNumber = IncidentSysID.Get(context);
            var body           = Body.Get(context);

            if (incidentNumber == null)
            {
                throw new ArgumentException("IncidentSysID");
            }

            if (body == null)
            {
                throw new ArgumentException("Body");
            }

            JObject jbody  = JsonConvert.DeserializeObject <JObject>(body);
            Object  jbody1 = jbody;

            //Console.WriteLine(jbody1.ToString());

            string uri = snowInstance + "/api/now/table/";

            Uri callUri = new Uri((uri), UriKind.Absolute);

            var client = new RestClient(callUri);

            client.Authenticator = new HttpBasicAuthenticator(userName, password);

            var request = new RestRequest("incident/" + incidentNumber, Method.PATCH);

            request.RequestFormat = DataFormat.Json;
            request.AddParameter("application/json", body, ParameterType.RequestBody);

            //request.AddParameter("application/json", "{\"urgency\":\"1\"}", ParameterType.RequestBody);
            //request.AddJsonBody(jbody);
            //request.AddBody(jbody);
            //request.AddBody(jbody1);

            IRestResponse response = client.Execute(request);

            JObject json = JsonConvert.DeserializeObject <JObject>(response.Content);

            JObject jr1 = JsonConvert.DeserializeObject <JObject>(json.SelectToken("result").ToString());

            IncidentObject.Set(context, jr1);

            //Console.WriteLine("upd - " + json.ToString());
        }
        protected override void Execute(CodeActivityContext context)
        {
            ServiceNowProp snowDetails = (ServiceNowProp)context.DataContext.GetProperties()["snowDetails"].GetValue(context.DataContext);

            var userName       = snowDetails.UserName;
            var password       = snowDetails.Password;
            var snowInstance   = snowDetails.SnowInstance;
            var incidentNumber = IncidentNumber.Get(context);

            if (incidentNumber == null)
            {
                throw new ArgumentException("IncidentNumber");
            }

            //Console.WriteLine("Incident Number - " + incidentNumber);

            Uri callUri = new Uri((snowInstance + "/api/now/table/incident?sysparm_query=number=" + incidentNumber), UriKind.Absolute);

            var client = new RestClient(callUri);

            client.Authenticator = new HttpBasicAuthenticator(userName, password);

            var request = new RestRequest(Method.GET);

            IRestResponse response = client.Execute(request);

            JObject json = JsonConvert.DeserializeObject <JObject>(response.Content);

            JArray jr1 = JsonConvert.DeserializeObject <JArray>(json.SelectToken("result").ToString());

            JObject final = JsonConvert.DeserializeObject <JObject>(jr1.First.ToString());

            //Console.WriteLine("response - " + response.Content);

            //Console.WriteLine("json - " + jr1.ToString());

            //Console.WriteLine("first - " + final.GetValue("sys_id"));

            //Object resp1 = json;

            IncidentJObject.Set(context, final);
        }
        protected override void Execute(CodeActivityContext context)
        {
            ServiceNowProp snowDetails = (ServiceNowProp)context.DataContext.GetProperties()["snowDetails"].GetValue(context.DataContext);

            var    userName     = snowDetails.UserName;
            var    password     = snowDetails.Password;
            var    snowInstance = snowDetails.SnowInstance;
            String sysparm      = SysParm_query.Get(context);
            string uri          = snowInstance + "/api/now/table/incident";

            if (sysparm != null)
            {
                uri = uri + "?sysparm_query=" + sysparm;
            }

            //Console.WriteLine("details - " + userName + password + snowInstance);

            Uri callUri = new Uri(uri, UriKind.Absolute);

            var client = new RestClient(callUri);

            client.Authenticator = new HttpBasicAuthenticator(userName, password);

            var request = new RestRequest(Method.GET);

            IRestResponse response = client.Execute(request);

            JObject json = JsonConvert.DeserializeObject <JObject>(response.Content);

            JArray jr1 = JsonConvert.DeserializeObject <JArray>(json.SelectToken("result").ToString());

            //Console.WriteLine("response - " + response.Content);

            //foreach ( JObject ob in jr1) {
            //    Console.WriteLine(ob.GetValue("number"));
            //}

            IncidentList.Set(context, jr1);
        }