Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jhon 87 posts 162 karma points
    Apr 19, 2018 @ 08:08
    Jhon
    0

    It is getting some error

    Hi Michael,

    Thanks for your help last time.

    I have written this code , it is displaying some error. See below my code

    enter image description here

    see my output error:

    enter image description here

    See my document type:

    enter image description here

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Apr 19, 2018 @ 08:26
    Michaël Vanbrabandt
    0

    Hi Jhon,

    no problem.

    For this thread I see you use Model.HasValue which doesn't exists.

    Make sure to always use Model.Content because its the Content property that contains the IPublishedContent object of your current page.

    Hope this helps!

    /Michaël

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Apr 19, 2018 @ 08:27
    Kevin Jump
    0

    Hi,

    I think you need to change the code to :

    if (!Model.Content.HasValue("linkPicker")) {
    

    and if you are not using the models from models builder

    node = Model.linkPicker 
    

    will need to become

        node = Model.Content.GetPropertyValue<IPublishedContent>("linkPicker")
    
  • Jhon 87 posts 162 karma points
    Apr 19, 2018 @ 08:46
    Jhon
    0

    Hi,

    Yes i have written. See my code . enter image description here

    See error:

    Compiler Error Message: The name 'node' does not exist in the current context

    enter image description here

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Apr 19, 2018 @ 08:57
    Kevin Jump
    0

    Hi

    i think that is a issue with the variable scope.

    in the if you have

    if (...) {
       var node = ...
    }
    else {
       node = 
    }
    

    which mean the node variable is only setup in the first if statement - and doesn't exist outside of that if block.

    so you need to move the delcleation out.

    Personally I would do :

    var node = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("linkPicker");
    if (node == null || !node.Any()) {
       node = ... the decendants stuff.
    }
    

    but

    if is worth noting you are returning two diffrent types of things from these statements as written in your code

    Model.Content.Decendents.Where(...) will return a collection of nodes (so and IEnumerable

    I didn't ask what type of picker linkPicker was (my bad) - but i assume its a MultiNodeTreePicker in which case you should change the GetPropertyValue<IPublishedContent> bit to GetPropertyValue<IEnumerable<IPublishedContent>>


    You don't always need the <>

    also check the IEnumerable bit - i am just typing this in the forums and oftem miss spell that !

  • Jhon 87 posts 162 karma points
    Apr 19, 2018 @ 09:20
    Jhon
    0

    Yes , The code is working.. I am using MultiNodeTreePicker. I want to check all process output. Thanks for you help.

Please Sign in or register to post replies

Write your reply to:

Draft